Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6787)

Unified Diff: chrome/browser/web_dev_style/js_checker_test.py

Issue 2624503002: Add web_dev_style presubmit to ensure <if>/<include> live in comments (Closed)
Patch Set: '<iframe' Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/web_dev_style/js_checker_test.py
diff --git a/chrome/browser/web_dev_style/js_checker_test.py b/chrome/browser/web_dev_style/js_checker_test.py
index 43574e1a5d64b3d925fd176e3cd42ea976043c72..b9ea46bf46f8b7c22f736341a1e030d4ae320a80 100755
--- a/chrome/browser/web_dev_style/js_checker_test.py
+++ b/chrome/browser/web_dev_style/js_checker_test.py
@@ -26,6 +26,44 @@ class JsCheckerTest(SuperMoxTestBase):
output_api = self.mox.CreateMockAnything()
self.checker = js_checker.JSChecker(input_api, output_api)
+ def ShouldFailCommentCheck(self, line):
+ """Checks that uncommented '<if>' and '<include>' are a style error."""
+ error = self.checker.CommentIfAndIncludeCheck(1, line)
+ self.assertNotEqual('', error, 'Should be flagged as style error: ' + line)
+ highlight = test_util.GetHighlight(line, error).strip()
+ self.assertTrue(highlight.startswith(('<if', '<include')))
+
+ def ShouldPassCommentCheck(self, line):
+ """Checks that commented '<if>' and '<include>' are allowed."""
+ self.assertEqual('', self.checker.CommentIfAndIncludeCheck(1, line),
+ 'Should not be flagged as style error: ' + line)
+
+ def testCommentFails(self):
+ lines = [
+ '<include src="blah.js">',
+ # Currently, only "// " is accepted (not just "//" or "//\s+") as Python
+ # can't do variable-length lookbehind.
+ '//<include src="blah.js">',
+ '// <include src="blah.js">',
+ ' <include src="blee.js">',
+ ' <if expr="chromeos">',
+ '<if expr="lang == \'de\'">',
+ '//<if expr="bitness == 64">',
+ ]
+ for line in lines:
+ self.ShouldFailCommentCheck(line)
+
+ def testCommentPasses(self):
+ lines = [
+ '// <include src="assert.js">',
+ ' // <include src="util.js"/>',
+ '// <if expr="chromeos">',
+ ' // <if expr="not chromeos">',
+ " '<iframe src=blah.html>';",
+ ]
+ for line in lines:
+ self.ShouldPassCommentCheck(line)
+
def ShouldFailConstCheck(self, line):
"""Checks that the 'const' checker flags |line| as a style error."""
error = self.checker.ConstCheck(1, line)
« no previous file with comments | « chrome/browser/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698