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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 self.assertFalse('var ' in highlight); | 363 self.assertFalse('var ' in highlight); |
364 | 364 |
365 def ShouldPassVarNameCheck(self, line): | 365 def ShouldPassVarNameCheck(self, line): |
366 """Checks that variableNamesLikeThis aren't style errors.""" | 366 """Checks that variableNamesLikeThis aren't style errors.""" |
367 self.assertEqual('', self.checker.VarNameCheck(1, line), | 367 self.assertEqual('', self.checker.VarNameCheck(1, line), |
368 msg='Should not be flagged as style error: ' + line) | 368 msg='Should not be flagged as style error: ' + line) |
369 | 369 |
370 def testVarNameFails(self): | 370 def testVarNameFails(self): |
371 lines = [ | 371 lines = [ |
372 "var private_;", | 372 "var private_;", |
| 373 "var hostName_ = 'https://google.com';", |
373 " var _super_private", | 374 " var _super_private", |
374 " var unix_hacker = someFunc();", | 375 " var unix_hacker = someFunc();", |
375 ] | 376 ] |
376 for line in lines: | 377 for line in lines: |
377 self.ShouldFailVarNameCheck(line) | 378 self.ShouldFailVarNameCheck(line) |
378 | 379 |
379 def testVarNamePasses(self): | 380 def testVarNamePasses(self): |
380 lines = [ | 381 lines = [ |
381 " var namesLikeThis = [];", | 382 " var namesLikeThis = [];", |
382 " for (var i = 0; i < 10; ++i) { ", | 383 " for (var i = 0; i < 10; ++i) { ", |
383 "for (var i in obj) {", | 384 "for (var i in obj) {", |
384 " var one, two, three;", | 385 " var one, two, three;", |
385 " var magnumPI = {};", | 386 " var magnumPI = {};", |
386 " var g_browser = 'da browzer';", | 387 " var g_browser = 'da browzer';", |
387 "/** @const */ var Bla = options.Bla;", # goog.scope() replacement. | 388 "/** @const */ var Bla = options.Bla;", # goog.scope() replacement. |
388 " var $ = function() {", # For legacy reasons. | 389 " var $ = function() {", # For legacy reasons. |
389 " var StudlyCaps = cr.define('bla')", # Classes. | 390 " var StudlyCaps = cr.define('bla')", # Classes. |
390 " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in | 391 " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in |
391 # front of all these vars like | 392 # front of all these vars like |
392 "/** @const */ CONST_VAR = 1;", # this line has (<--). | 393 "/** @const */ CONST_VAR = 1;", # this line has (<--). |
393 ] | 394 ] |
394 for line in lines: | 395 for line in lines: |
395 self.ShouldPassVarNameCheck(line) | 396 self.ShouldPassVarNameCheck(line) |
396 | 397 |
397 | 398 |
398 if __name__ == '__main__': | 399 if __name__ == '__main__': |
399 unittest.main() | 400 unittest.main() |
OLD | NEW |