| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import js_checker | 6 import js_checker |
| 7 from os import path as os_path | 7 from os import path as os_path |
| 8 import re | 8 import re |
| 9 from sys import path as sys_path | 9 from sys import path as sys_path |
| 10 import test_util | 10 import test_util |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 def testInheritDocPasses(self): | 233 def testInheritDocPasses(self): |
| 234 lines = [ | 234 lines = [ |
| 235 "And then I said, but I won't @inheritDoc! Hahaha!", | 235 "And then I said, but I won't @inheritDoc! Hahaha!", |
| 236 " If your dad's a doctor, do you inheritDoc?", | 236 " If your dad's a doctor, do you inheritDoc?", |
| 237 " What's up, inherit doc?", | 237 " What's up, inherit doc?", |
| 238 " this.inheritDoc(someDoc)", | 238 " this.inheritDoc(someDoc)", |
| 239 ] | 239 ] |
| 240 for line in lines: | 240 for line in lines: |
| 241 self.ShouldPassInheritDocCheck(line) | 241 self.ShouldPassInheritDocCheck(line) |
| 242 | 242 |
| 243 def ShouldFailPolymerLocalIdCheck(self, line): |
| 244 """Checks that element.$.localId check marks |line| as a style error.""" |
| 245 error = self.checker.PolymerLocalIdCheck(1, line) |
| 246 self.assertNotEqual('', error, |
| 247 msg='Should be flagged as a style error: ' + line) |
| 248 self.assertTrue('.$' in test_util.GetHighlight(line, error)) |
| 249 |
| 250 def ShouldPassPolymerLocalIdCheck(self, line): |
| 251 """Checks that element.$.localId check doesn't mark |line| as a style |
| 252 error.""" |
| 253 self.assertEqual('', self.checker.PolymerLocalIdCheck(1, line), |
| 254 msg='Should not be flagged as a style error: ' + line) |
| 255 |
| 256 def testPolymerLocalIdFails(self): |
| 257 lines = [ |
| 258 "cat.$.dog", |
| 259 "thing1.$.thing2", |
| 260 "element.$.localId", |
| 261 "element.$['fancy-hyphenated-id']", |
| 262 ] |
| 263 for line in lines: |
| 264 self.ShouldFailPolymerLocalIdCheck(line) |
| 265 |
| 266 def testPolymerLocalIdPasses(self): |
| 267 lines = [ |
| 268 "this.$.id", |
| 269 "this.$.localId", |
| 270 "this.$['fancy-id']", |
| 271 ] |
| 272 for line in lines: |
| 273 self.ShouldPassPolymerLocalIdCheck(line) |
| 274 |
| 243 def ShouldFailWrapperTypeCheck(self, line): | 275 def ShouldFailWrapperTypeCheck(self, line): |
| 244 """Checks that the use of wrapper types (i.e. new Number(), @type {Number}) | 276 """Checks that the use of wrapper types (i.e. new Number(), @type {Number}) |
| 245 is a style error. | 277 is a style error. |
| 246 """ | 278 """ |
| 247 error = self.checker.WrapperTypeCheck(1, line) | 279 error = self.checker.WrapperTypeCheck(1, line) |
| 248 self.assertNotEqual('', error, | 280 self.assertNotEqual('', error, |
| 249 msg='Should be flagged as style error: ' + line) | 281 msg='Should be flagged as style error: ' + line) |
| 250 highlight = test_util.GetHighlight(line, error) | 282 highlight = test_util.GetHighlight(line, error) |
| 251 self.assertTrue(highlight in ('Boolean', 'Number', 'String')) | 283 self.assertTrue(highlight in ('Boolean', 'Number', 'String')) |
| 252 | 284 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in | 352 " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in |
| 321 # front of all these vars like | 353 # front of all these vars like |
| 322 "/** @const */ CONST_VAR = 1;", # this line has (<--). | 354 "/** @const */ CONST_VAR = 1;", # this line has (<--). |
| 323 ] | 355 ] |
| 324 for line in lines: | 356 for line in lines: |
| 325 self.ShouldPassVarNameCheck(line) | 357 self.ShouldPassVarNameCheck(line) |
| 326 | 358 |
| 327 | 359 |
| 328 if __name__ == '__main__': | 360 if __name__ == '__main__': |
| 329 unittest.main() | 361 unittest.main() |
| OLD | NEW |