Chromium Code Reviews| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 | 196 |
| 197 def testExtraDotInGenericFails(self): | 197 def testExtraDotInGenericFails(self): |
| 198 lines = [ | 198 lines = [ |
| 199 "/** @private {!Array.<!Frobber>} */", | 199 "/** @private {!Array.<!Frobber>} */", |
| 200 "var a = /** @type {Object.<number>} */({});", | 200 "var a = /** @type {Object.<number>} */({});", |
| 201 "* @return {!Promise.<Change>}" | 201 "* @return {!Promise.<Change>}" |
| 202 ] | 202 ] |
| 203 for line in lines: | 203 for line in lines: |
| 204 self.ShouldFailExtraDotInGenericCheck(line) | 204 self.ShouldFailExtraDotInGenericCheck(line) |
| 205 | 205 |
| 206 def ShouldFailGetElementByIdCheck(self, line): | |
|
Dan Beam
2017/05/30 16:17:26
can we leave some of these?
dpapad
2017/05/30 17:08:24
We would need to modify those tests to run self.ch
Dan Beam
2017/05/30 17:11:41
yes
dpapad
2017/05/30 18:30:15
Trying to address this comment, but I keep hitting
Dan Beam
2017/05/30 20:33:30
i think we should only use SuperMoxTestBase if it'
dpapad
2017/05/30 22:11:21
I am restoring similar tests at https://codereview
| |
| 207 """Checks that the 'getElementById' checker flags |line| as a style | |
| 208 error. | |
| 209 """ | |
| 210 error = self.checker.GetElementByIdCheck(1, line) | |
| 211 self.assertNotEqual('', error, | |
| 212 'Should be flagged as style error: ' + line) | |
| 213 self.assertEqual(test_util.GetHighlight(line, error), | |
| 214 'document.getElementById') | |
| 215 | |
| 216 def ShouldPassGetElementByIdCheck(self, line): | |
| 217 """Checks that the 'getElementById' checker doesn't flag |line| as a style | |
| 218 error. | |
| 219 """ | |
| 220 self.assertEqual('', self.checker.GetElementByIdCheck(1, line), | |
| 221 'Should not be flagged as style error: ' + line) | |
| 222 | |
| 223 def testGetElementByIdFails(self): | |
| 224 lines = [ | |
| 225 "document.getElementById('foo');", | |
| 226 " document.getElementById('foo');", | |
| 227 "var x = document.getElementById('foo');", | |
| 228 "if (document.getElementById('foo').hidden) {", | |
| 229 ] | |
| 230 for line in lines: | |
| 231 self.ShouldFailGetElementByIdCheck(line) | |
| 232 | |
| 233 def testGetElementByIdPasses(self): | |
| 234 lines = [ | |
| 235 "elem.ownerDocument.getElementById('foo');", | |
| 236 " elem.ownerDocument.getElementById('foo');", | |
| 237 "var x = elem.ownerDocument.getElementById('foo');", | |
| 238 "if (elem.ownerDocument.getElementById('foo').hidden) {", | |
| 239 "doc.getElementById('foo');", | |
| 240 " doc.getElementById('foo');", | |
| 241 "cr.doc.getElementById('foo');", | |
| 242 " cr.doc.getElementById('foo');", | |
| 243 "var x = doc.getElementById('foo');", | |
| 244 "if (doc.getElementById('foo').hidden) {", | |
| 245 ] | |
| 246 for line in lines: | |
| 247 self.ShouldPassGetElementByIdCheck(line) | |
| 248 | |
| 249 def ShouldFailInheritDocCheck(self, line): | 206 def ShouldFailInheritDocCheck(self, line): |
| 250 """Checks that the '@inheritDoc' checker flags |line| as a style error.""" | 207 """Checks that the '@inheritDoc' checker flags |line| as a style error.""" |
| 251 error = self.checker.InheritDocCheck(1, line) | 208 error = self.checker.InheritDocCheck(1, line) |
| 252 self.assertNotEqual('', error, | 209 self.assertNotEqual('', error, |
| 253 msg='Should be flagged as style error: ' + line) | 210 msg='Should be flagged as style error: ' + line) |
| 254 self.assertEqual(test_util.GetHighlight(line, error), '@inheritDoc') | 211 self.assertEqual(test_util.GetHighlight(line, error), '@inheritDoc') |
| 255 | 212 |
| 256 def ShouldPassInheritDocCheck(self, line): | 213 def ShouldPassInheritDocCheck(self, line): |
| 257 """Checks that the '@inheritDoc' checker doesn't flag |line| as a style | 214 """Checks that the '@inheritDoc' checker doesn't flag |line| as a style |
| 258 error. | 215 error. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in | 348 " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in |
| 392 # front of all these vars like | 349 # front of all these vars like |
| 393 "/** @const */ CONST_VAR = 1;", # this line has (<--). | 350 "/** @const */ CONST_VAR = 1;", # this line has (<--). |
| 394 ] | 351 ] |
| 395 for line in lines: | 352 for line in lines: |
| 396 self.ShouldPassVarNameCheck(line) | 353 self.ShouldPassVarNameCheck(line) |
| 397 | 354 |
| 398 | 355 |
| 399 if __name__ == '__main__': | 356 if __name__ == '__main__': |
| 400 unittest.main() | 357 unittest.main() |
| OLD | NEW |