| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 from os import path as os_path | |
| 7 import re | |
| 8 import resource_checker | |
| 9 from sys import path as sys_path | |
| 10 import test_util | |
| 11 import unittest | |
| 12 | |
| 13 _HERE = os_path.dirname(os_path.abspath(__file__)) | |
| 14 sys_path.append(os_path.join(_HERE, '..', '..', '..', 'build')) | |
| 15 | |
| 16 import find_depot_tools # pylint: disable=W0611 | |
| 17 from testing_support.super_mox import SuperMoxTestBase | |
| 18 | |
| 19 | |
| 20 class ResourceCheckerTest(SuperMoxTestBase): | |
| 21 def setUp(self): | |
| 22 SuperMoxTestBase.setUp(self) | |
| 23 | |
| 24 input_api = self.mox.CreateMockAnything() | |
| 25 input_api.re = re | |
| 26 output_api = self.mox.CreateMockAnything() | |
| 27 self.checker = resource_checker.ResourceChecker(input_api, output_api) | |
| 28 | |
| 29 def ShouldFailIncludeCheck(self, line): | |
| 30 """Checks that the '</include>' checker flags |line| as a style error.""" | |
| 31 error = self.checker.IncludeCheck(1, line) | |
| 32 self.assertNotEqual('', error, | |
| 33 'Should be flagged as style error: ' + line) | |
| 34 highlight = test_util.GetHighlight(line, error).strip() | |
| 35 self.assertTrue('include' in highlight and highlight[0] == '<') | |
| 36 | |
| 37 def ShouldPassIncludeCheck(self, line): | |
| 38 """Checks that the '</include>' checker doesn't flag |line| as an error.""" | |
| 39 self.assertEqual('', self.checker.IncludeCheck(1, line), | |
| 40 'Should not be flagged as style error: ' + line) | |
| 41 | |
| 42 def testIncludeFails(self): | |
| 43 lines = [ | |
| 44 "</include> ", | |
| 45 " </include>", | |
| 46 " </include> ", | |
| 47 ' <include src="blah.js" /> ', | |
| 48 '<include src="blee.js"/>', | |
| 49 ] | |
| 50 for line in lines: | |
| 51 self.ShouldFailIncludeCheck(line) | |
| 52 | |
| 53 def testIncludePasses(self): | |
| 54 lines = [ | |
| 55 '<include src="assert.js">', | |
| 56 "<include src='../../assert.js'>", | |
| 57 "<i>include src='blah'</i>", | |
| 58 "</i>nclude", | |
| 59 "</i>include", | |
| 60 ] | |
| 61 for line in lines: | |
| 62 self.ShouldPassIncludeCheck(line) | |
| 63 | |
| 64 | |
| 65 if __name__ == '__main__': | |
| 66 unittest.main() | |
| OLD | NEW |