| OLD | NEW |
| 1 # Copyright 2013 the V8 project authors. All rights reserved. | 1 # Copyright 2013 the V8 project authors. All rights reserved. |
| 2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
| 3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
| 4 # met: | 4 # met: |
| 5 # | 5 # |
| 6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
| 9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
| 10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 (".*", ["", "a", "abcaabbcc"], []), | 52 (".*", ["", "a", "abcaabbcc"], []), |
| 53 ("a.b", ["aab", "abb", "acb"], ["ab", ""]), | 53 ("a.b", ["aab", "abb", "acb"], ["ab", ""]), |
| 54 ("a.?b", ["aab", "abb", "acb", "ab"], ["aaab", ""]), | 54 ("a.?b", ["aab", "abb", "acb", "ab"], ["aaab", ""]), |
| 55 ("a.+b", ["aab", "abb", "acb"], ["aaac", "ab", ""]), | 55 ("a.+b", ["aab", "abb", "acb"], ["aaac", "ab", ""]), |
| 56 (".|.", ["a", "b"], ["aa", ""]), | 56 (".|.", ["a", "b"], ["aa", ""]), |
| 57 ("//.", ["//a"], ["aa", ""]), | 57 ("//.", ["//a"], ["aa", ""]), |
| 58 ("[ab]{2}", ["aa", "ab", "ba", "bb"], ["", "a", "b", "aaa", "bbb"]), | 58 ("[ab]{2}", ["aa", "ab", "ba", "bb"], ["", "a", "b", "aaa", "bbb"]), |
| 59 ("[ab]{2,3}", ["aa", "ab", "ba", "bb", "aab", "baa", "bbb"], | 59 ("[ab]{2,3}", ["aa", "ab", "ba", "bb", "aab", "baa", "bbb"], |
| 60 ["", "a", "b", "aaaa", "bbba"]), | 60 ["", "a", "b", "aaaa", "bbba"]), |
| 61 ("[ab]{2,4}", ["aa", "ab", "ba", "bb", "aab", "baa", "bbb", "abab"], | 61 ("[ab]{2,4}", ["aa", "ab", "ba", "bb", "aab", "baa", "bbb", "abab"], |
| 62 ["", "a", "b", "aaaba", "bbbaa"]) | 62 ["", "a", "b", "aaaba", "bbbaa"]), |
| 63 ("[\\101]", ["A"], ["B"]) |
| 63 ] | 64 ] |
| 64 | 65 |
| 65 def test_matches(self): | 66 def test_matches(self): |
| 66 for (regex, matches, not_matches) in self.__test_data: | 67 for (regex, matches, not_matches) in self.__test_data: |
| 67 (nfa, dfa) = build_automata(regex) | 68 (nfa, dfa) = build_automata(regex) |
| 68 for string in matches: | 69 for string in matches: |
| 69 self.assertTrue(nfa.matches(string)) | 70 self.assertTrue(nfa.matches(string)) |
| 70 self.assertTrue(dfa.matches(string)) | 71 self.assertTrue(dfa.matches(string)) |
| 71 for string in not_matches: | 72 for string in not_matches: |
| 72 self.assertFalse(nfa.matches(string)) | 73 self.assertFalse(nfa.matches(string)) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 98 def verify_hit(string, expected): | 99 def verify_hit(string, expected): |
| 99 verify(string, expected + [('TERMINATE',)]) | 100 verify(string, expected + [('TERMINATE',)]) |
| 100 (l, r) = left_action, right_action | 101 (l, r) = left_action, right_action |
| 101 verify_hit("left", [l]) | 102 verify_hit("left", [l]) |
| 102 verify_miss("lefta", [l]) | 103 verify_miss("lefta", [l]) |
| 103 verify_hit("leftrightleftright", [l, r, l, r]) | 104 verify_hit("leftrightleftright", [l, r, l, r]) |
| 104 verify_miss("leftrightleftrightx", [l, r, l, r]) | 105 verify_miss("leftrightleftrightx", [l, r, l, r]) |
| 105 | 106 |
| 106 if __name__ == '__main__': | 107 if __name__ == '__main__': |
| 107 unittest.main() | 108 unittest.main() |
| OLD | NEW |