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

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

Issue 50293010: Experimental parser: parse character classes (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: 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 | « tools/lexer_generator/regex_parser.py ('k') | tools/lexer_generator/transition_keys.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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 def test_hash(self): 44 def test_hash(self):
45 for (left, right) in self.__equal_pairs: 45 for (left, right) in self.__equal_pairs:
46 self.assertEqual(hash(left), hash(right)) 46 self.assertEqual(hash(left), hash(right))
47 47
48 def test_classes(self): 48 def test_classes(self):
49 # class regex, should match, should not match 49 # class regex, should match, should not match
50 data = [ 50 data = [
51 ("1-2", "12", "ab"), 51 ("1-2", "12", "ab"),
52 ("a-zA-Z", "abyzABYZ" , "123"), 52 ("a-zA-Z", "abyzABYZ" , "123"),
53 ("a-zA-Z0g" , "abyzABYZ0" , "123"), 53 ("a-zA-Z0g" , "abyzABYZ0" , "123"),
54 ("a-z:ws::lit:" , "abc" , "123"),
54 ] 55 ]
55 for (string, match, no_match) in data: 56 for (string, match, no_match) in data:
56 for invert in [False, True]: 57 for invert in [False, True]:
57 if invert: 58 if invert:
58 regex = "[^%s]" % string 59 regex = "[^%s]" % string
59 token = "NOT_CLASS" 60 token = "NOT_CLASS"
60 else: 61 else:
61 regex = "[%s]" % string 62 regex = "[%s]" % string
62 token = "CLASS" 63 token = "CLASS"
63 graph = RegexParser.parse(regex) 64 graph = RegexParser.parse(regex)
64 assert graph[0] == token 65 assert graph[0] == token
65 key = TransitionKey.character_class(invert, graph[1]) 66 key = TransitionKey.character_class(invert, graph[1])
66 for c in match: 67 for c in match:
67 self.assertEqual(invert, not key.matches_char(c)) 68 self.assertEqual(invert, not key.matches_char(c))
68 for c in no_match: 69 for c in no_match:
69 self.assertEqual(invert, key.matches_char(c)) 70 self.assertEqual(invert, key.matches_char(c))
70 71
71 if __name__ == '__main__': 72 if __name__ == '__main__':
72 unittest.main() 73 unittest.main()
OLDNEW
« no previous file with comments | « tools/lexer_generator/regex_parser.py ('k') | tools/lexer_generator/transition_keys.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698