OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Unit tests for Web Development Style Guide checker.""" | 6 """Unit tests for Web Development Style Guide checker.""" |
7 | 7 |
8 import os | 8 import os |
9 import re | 9 import re |
10 import sys | 10 import sys |
11 import unittest | 11 import unittest |
12 | 12 |
13 test_dir = os.path.dirname(os.path.abspath(__file__)) | 13 test_dir = os.path.dirname(os.path.abspath(__file__)) |
14 sys.path.extend([ | 14 sys.path.extend([ |
15 os.path.normpath(os.path.join(test_dir, '..', '..', 'tools')), | 15 os.path.normpath(os.path.join(test_dir, '..', '..', 'tools')), |
16 os.path.join(test_dir), | 16 os.path.join(test_dir), |
17 ]) | 17 ]) |
18 | 18 |
19 import find_depot_tools # pylint: disable=W0611 | 19 import find_depot_tools # pylint: disable=W0611 |
20 from testing_support.super_mox import SuperMoxTestBase | 20 from testing_support.super_mox import SuperMoxTestBase |
21 from web_dev_style import resource_checker, css_checker, js_checker # pylint: di
sable=F0401 | 21 from web_dev_style import css_checker, html_checker, js_checker, \ |
| 22 resource_checker # pylint: disable=F0401 |
22 | 23 |
23 | 24 |
24 def GetHighlight(line, error): | 25 def GetHighlight(line, error): |
25 """Returns the substring of |line| that is highlighted in |error|.""" | 26 """Returns the substring of |line| that is highlighted in |error|.""" |
26 error_lines = error.split('\n') | 27 error_lines = error.split('\n') |
27 highlight = error_lines[error_lines.index(line) + 1] | 28 highlight = error_lines[error_lines.index(line) + 1] |
28 return ''.join(ch1 for (ch1, ch2) in zip(line, highlight) if ch2 == '^') | 29 return ''.join(ch1 for (ch1, ch2) in zip(line, highlight) if ch2 == '^') |
29 | 30 |
30 | 31 |
| 32 class HtmlStyleTest(SuperMoxTestBase): |
| 33 def setUp(self): |
| 34 SuperMoxTestBase.setUp(self) |
| 35 |
| 36 input_api = self.mox.CreateMockAnything() |
| 37 input_api.re = re |
| 38 output_api = self.mox.CreateMockAnything() |
| 39 self.checker = html_checker.HtmlChecker(input_api, output_api) |
| 40 |
| 41 def ShouldFailLabelCheck(self, line): |
| 42 """Checks that the label checker flags |line| as a style error.""" |
| 43 error = self.checker.LabelCheck(1, line) |
| 44 self.assertNotEqual('', error, 'Should be flagged as style error: ' + line) |
| 45 highlight = GetHighlight(line, error).strip() |
| 46 self.assertEqual('for=', highlight) |
| 47 |
| 48 def ShouldPassLabelCheck(self, line): |
| 49 """Checks that the label checker doesn't flag |line| as a style error.""" |
| 50 error = self.checker.LabelCheck(1, line) |
| 51 self.assertEqual('', error, 'Should not be flagged as style error: ' + line) |
| 52 |
| 53 def testForAttributeFails(self): |
| 54 lines = [ |
| 55 " for=\"abc\"", |
| 56 "for= ", |
| 57 " \tfor= ", |
| 58 " for=" |
| 59 ] |
| 60 for line in lines: |
| 61 self.ShouldFailLabelCheck(line) |
| 62 |
| 63 def testOtherAttributesPass(self): |
| 64 lines = [ |
| 65 " my-for=\"abc\" ", |
| 66 " myfor=\"abc\" ", |
| 67 " <for", |
| 68 ] |
| 69 for line in lines: |
| 70 self.ShouldPassLabelCheck(line) |
| 71 |
| 72 |
31 class ResourceStyleGuideTest(SuperMoxTestBase): | 73 class ResourceStyleGuideTest(SuperMoxTestBase): |
32 def setUp(self): | 74 def setUp(self): |
33 SuperMoxTestBase.setUp(self) | 75 SuperMoxTestBase.setUp(self) |
34 | 76 |
35 input_api = self.mox.CreateMockAnything() | 77 input_api = self.mox.CreateMockAnything() |
36 input_api.re = re | 78 input_api.re = re |
37 output_api = self.mox.CreateMockAnything() | 79 output_api = self.mox.CreateMockAnything() |
38 self.checker = resource_checker.ResourceChecker(input_api, output_api) | 80 self.checker = resource_checker.ResourceChecker(input_api, output_api) |
39 | 81 |
40 def ShouldFailIncludeCheck(self, line): | 82 def ShouldFailIncludeCheck(self, line): |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 opacity: .0; | 869 opacity: .0; |
828 opacity: 0.0; | 870 opacity: 0.0; |
829 opacity: 0.; | 871 opacity: 0.; |
830 border-width: 0mm; | 872 border-width: 0mm; |
831 height: 0cm; | 873 height: 0cm; |
832 width: 0in; | 874 width: 0in; |
833 """) | 875 """) |
834 | 876 |
835 if __name__ == '__main__': | 877 if __name__ == '__main__': |
836 unittest.main() | 878 unittest.main() |
OLD | NEW |