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

Side by Side Diff: tools/lexer_generator/automata_test.py

Issue 59953002: Experimental lexer generator: parse {} in regexps. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: rebased Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/lexer_generator/nfa.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 ("a?b", ["ab", "b"], ["a", "c", ""]), 48 ("a?b", ["ab", "b"], ["a", "c", ""]),
49 ("a*b", ["ab", "aaab", "b"], ["a", "c", ""]), 49 ("a*b", ["ab", "aaab", "b"], ["a", "c", ""]),
50 ("a|b", ["a", "b"], ["ab", "c", ""]), 50 ("a|b", ["a", "b"], ["ab", "c", ""]),
51 (".", ["a", "b"], ["", "aa"]), 51 (".", ["a", "b"], ["", "aa"]),
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"]),
59 ("[ab]{2,3}", ["aa", "ab", "ba", "bb", "aab", "baa", "bbb"],
60 ["", "a", "b", "aaaa", "bbba"]),
61 ("[ab]{2,4}", ["aa", "ab", "ba", "bb", "aab", "baa", "bbb", "abab"],
62 ["", "a", "b", "aaaba", "bbbaa"])
58 ] 63 ]
59 64
60 def test_matches(self): 65 def test_matches(self):
61 for (regex, matches, not_matches) in self.__test_data: 66 for (regex, matches, not_matches) in self.__test_data:
62 (nfa, dfa) = build_automata(regex) 67 (nfa, dfa) = build_automata(regex)
63 for string in matches: 68 for string in matches:
64 self.assertTrue(nfa.matches(string)) 69 self.assertTrue(nfa.matches(string))
65 self.assertTrue(dfa.matches(string)) 70 self.assertTrue(dfa.matches(string))
66 for string in not_matches: 71 for string in not_matches:
67 self.assertFalse(nfa.matches(string)) 72 self.assertFalse(nfa.matches(string))
(...skipping 25 matching lines...) Expand all
93 def verify_hit(string, expected): 98 def verify_hit(string, expected):
94 verify(string, expected + [('TERMINATE',)]) 99 verify(string, expected + [('TERMINATE',)])
95 (l, r) = left_action, right_action 100 (l, r) = left_action, right_action
96 verify_hit("left", [l]) 101 verify_hit("left", [l])
97 verify_miss("lefta", [l]) 102 verify_miss("lefta", [l])
98 verify_hit("leftrightleftright", [l, r, l, r]) 103 verify_hit("leftrightleftright", [l, r, l, r])
99 verify_miss("leftrightleftrightx", [l, r, l, r]) 104 verify_miss("leftrightleftrightx", [l, r, l, r])
100 105
101 if __name__ == '__main__': 106 if __name__ == '__main__':
102 unittest.main() 107 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/nfa.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698