| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2013 The Closure Linter Authors. All Rights Reserved. | |
| 3 # | |
| 4 # Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 # you may not use this file except in compliance with the License. | |
| 6 # You may obtain a copy of the License at | |
| 7 # | |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 # | |
| 10 # Unless required by applicable law or agreed to in writing, software | |
| 11 # distributed under the License is distributed on an "AS-IS" BASIS, | |
| 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 # See the License for the specific language governing permissions and | |
| 14 # limitations under the License. | |
| 15 | |
| 16 """ | |
| 17 Tests for trailing commas (ES3) errors | |
| 18 | |
| 19 """ | |
| 20 | |
| 21 | |
| 22 import gflags as flags | |
| 23 import unittest as googletest | |
| 24 | |
| 25 from closure_linter import errors | |
| 26 from closure_linter import runner | |
| 27 from closure_linter.common import erroraccumulator | |
| 28 | |
| 29 flags.FLAGS.check_trailing_comma = True | |
| 30 class TrailingCommaTest(googletest.TestCase): | |
| 31 """Test case to for gjslint errorrules.""" | |
| 32 | |
| 33 def testGetTrailingCommaArray(self): | |
| 34 """ warning for trailing commas before closing array | |
| 35 """ | |
| 36 original = ['q = [1,]', ] | |
| 37 | |
| 38 # Expect line too long. | |
| 39 expected = errors.COMMA_AT_END_OF_LITERAL | |
| 40 | |
| 41 self._AssertInError(original, expected) | |
| 42 | |
| 43 def testGetTrailingCommaDict(self): | |
| 44 """ warning for trailing commas before closing array | |
| 45 """ | |
| 46 original = ['q = {1:1,}', ] | |
| 47 | |
| 48 # Expect line too long. | |
| 49 expected = errors.COMMA_AT_END_OF_LITERAL | |
| 50 | |
| 51 self._AssertInError(original, expected) | |
| 52 | |
| 53 def _AssertInError(self, original, expected): | |
| 54 """Asserts that the error fixer corrects original to expected.""" | |
| 55 | |
| 56 # Trap gjslint's output parse it to get messages added. | |
| 57 error_accumulator = erroraccumulator.ErrorAccumulator() | |
| 58 runner.Run('testing.js', error_accumulator, source=original) | |
| 59 error_nums = [e.code for e in error_accumulator.GetErrors()] | |
| 60 | |
| 61 self.assertIn(expected, error_nums) | |
| 62 | |
| 63 if __name__ == '__main__': | |
| 64 googletest.main() | |
| OLD | NEW |