| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2017 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 import unittest |
| 7 |
| 8 import match_util |
| 9 import re |
| 10 |
| 11 |
| 12 class MatchHelperTest(unittest.TestCase): |
| 13 |
| 14 def testExpandRegexIdentifierPlaceholder(self): |
| 15 def matches(pattern, target): |
| 16 regex = re.compile(match_util.ExpandRegexIdentifierPlaceholder(pattern)) |
| 17 return bool(regex.search(target) and regex.search(' %s ' % target)) |
| 18 |
| 19 self.assertTrue(matches(r'{{hello_world}}', 'helloWorld')) |
| 20 self.assertTrue(matches(r'{{hello_world}}', 'HelloWorld')) |
| 21 self.assertTrue(matches(r'{{hello_world}}', 'kHelloWorld')) |
| 22 self.assertTrue(matches(r'{{hello_world}}', 'hello_world')) |
| 23 self.assertTrue(matches(r'{{hello_world}}', '_hello_world')) |
| 24 self.assertTrue(matches(r'{{hello_world}}', 'hello_world_}}')) |
| 25 self.assertTrue(matches(r'{{hello_world}}', 'HELLO_WORLD')) |
| 26 self.assertTrue(matches(r'{{hello_world}}', 'HELLO_WORLD1')) |
| 27 self.assertTrue(matches(r'{{hello_world}}', 'kHelloWorld1')) |
| 28 self.assertFalse(matches(r'{{hello_world}}', 'hello world')) |
| 29 self.assertFalse(matches(r'{{hello_world}}', 'helloworld')) |
| 30 self.assertFalse(matches(r'{{hello_world}}', 'f_hello_world')) |
| 31 self.assertFalse(matches(r'{{hello_world}}', 'hello_world_f')) |
| 32 self.assertFalse(matches(r'{{hello_world}}', 'hello/world')) |
| 33 self.assertFalse(matches(r'{{hello_world}}', 'helloWORLD')) |
| 34 self.assertFalse(matches(r'{{hello_world}}', 'HELLOworld')) |
| 35 self.assertFalse(matches(r'{{hello_world}}', 'HELLOWORLD')) |
| 36 self.assertFalse(matches(r'{{hello_world}}', 'FOO_HELLO_WORLD')) |
| 37 self.assertFalse(matches(r'{{hello_world}}', 'HELLO_WORLD_BAR')) |
| 38 self.assertFalse(matches(r'{{hello_world}}', 'FooHelloWorld')) |
| 39 self.assertFalse(matches(r'{{hello_world}}', 'HelloWorldBar')) |
| 40 self.assertFalse(matches(r'{{hello_world}}', 'foohello/world')) |
| 41 self.assertFalse(matches(r'{{hello_world}}', '1HELLO_WORLD')) |
| 42 |
| 43 self.assertTrue(matches(r'{{_hello_world_}}', 'helloWorld')) |
| 44 self.assertTrue(matches(r'{{_hello_world_}}', 'HelloWorld')) |
| 45 self.assertTrue(matches(r'{{_hello_world_}}', 'kHelloWorld')) |
| 46 self.assertTrue(matches(r'{{_hello_world_}}', 'hello_world')) |
| 47 self.assertTrue(matches(r'{{_hello_world_}}', '_hello_world')) |
| 48 self.assertTrue(matches(r'{{_hello_world_}}', 'hello_world_')) |
| 49 self.assertTrue(matches(r'{{_hello_world_}}', 'HELLO_WORLD')) |
| 50 self.assertTrue(matches(r'{{_hello_world_}}', 'HELLO_WORLD1')) |
| 51 self.assertTrue(matches(r'{{_hello_world_}}', 'kHelloWorld1')) |
| 52 self.assertFalse(matches(r'{{_hello_world_}}', 'hello world')) |
| 53 self.assertFalse(matches(r'{{_hello_world_}}', 'helloworld')) |
| 54 self.assertTrue(matches(r'{{_hello_world_}}', 'f_hello_world')) |
| 55 self.assertTrue(matches(r'{{_hello_world_}}', 'hello_world_f')) |
| 56 self.assertFalse(matches(r'{{_hello_world_}}', 'hello/world')) |
| 57 self.assertFalse(matches(r'{{_hello_world_}}', 'helloWORLD')) |
| 58 self.assertFalse(matches(r'{{_hello_world_}}', 'HELLOworld')) |
| 59 self.assertFalse(matches(r'{{_hello_world_}}', 'HELLOWORLD')) |
| 60 self.assertTrue(matches(r'{{_hello_world_}}', 'FOO_HELLO_WORLD')) |
| 61 self.assertTrue(matches(r'{{_hello_world_}}', 'HELLO_WORLD_BAR')) |
| 62 self.assertTrue(matches(r'{{_hello_world_}}', 'FooHelloWorld')) |
| 63 self.assertTrue(matches(r'{{_hello_world_}}', 'HelloWorldBar')) |
| 64 self.assertFalse(matches(r'{{_hello_world_}}', 'foohello/world')) |
| 65 self.assertFalse(matches(r'{{_hello_world_}}', '1HELLO_WORLD')) |
| 66 |
| 67 |
| 68 if __name__ == '__main__': |
| 69 unittest.main() |
| OLD | NEW |