3 # Copyright 2012 The Closure Linter Authors. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS-IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 """Unit tests for RequireProvideSorter."""
21 import unittest as googletest
22 from closure_linter import ecmametadatapass
23 from closure_linter import javascripttokenizer
24 from closure_linter import javascripttokens
25 from closure_linter import requireprovidesorter
27 # pylint: disable-msg=C6409
28 TokenType = javascripttokens.JavaScriptTokenType
31 class RequireProvideSorterTest(googletest.TestCase):
32 """Tests for RequireProvideSorter."""
34 _tokenizer = javascripttokenizer.JavaScriptTokenizer()
35 _metadata_pass = ecmametadatapass.EcmaMetaDataPass()
37 def testFixRequires_removeBlankLines(self):
38 """Tests that blank lines are omitted in sorted goog.require statements."""
40 'goog.provide(\'package.subpackage.Whatever\');',
42 'goog.require(\'package.subpackage.ClassB\');',
44 'goog.require(\'package.subpackage.ClassA\');'
47 'goog.provide(\'package.subpackage.Whatever\');',
49 'goog.require(\'package.subpackage.ClassA\');',
50 'goog.require(\'package.subpackage.ClassB\');'
52 token = self._tokenizer.TokenizeFile(input_lines)
53 self._metadata_pass.Reset()
54 self._metadata_pass.Process(token)
56 sorter = requireprovidesorter.RequireProvideSorter()
57 sorter.FixRequires(token)
59 self.assertEquals(expected_lines, self._GetLines(token))
61 def _GetLines(self, token):
62 """Returns an array of lines based on the specified token stream."""
67 if token.IsLastInLine():
73 if __name__ == '__main__':