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

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

Issue 137883006: Experimental parser: use Terms instead of tuples (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 10 months 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/term_test.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 classes = {} 59 classes = {}
60 encoding = self.__encoding 60 encoding = self.__encoding
61 for (string, match, no_match) in data: 61 for (string, match, no_match) in data:
62 for invert in [False, True]: 62 for invert in [False, True]:
63 if invert: 63 if invert:
64 regex = "[^%s]" % string 64 regex = "[^%s]" % string
65 token = "NOT_CLASS" 65 token = "NOT_CLASS"
66 else: 66 else:
67 regex = "[%s]" % string 67 regex = "[%s]" % string
68 token = "CLASS" 68 token = "CLASS"
69 graph = RegexParser.parse(regex) 69 term = RegexParser.parse(regex)
70 assert graph[0] == token 70 assert term.name() == token
71 key = TransitionKey.character_class(encoding, graph, classes) 71 key = TransitionKey.character_class(encoding, term, classes)
72 for c in match: 72 for c in match:
73 self.assertEqual(invert, not key.matches_char(c)) 73 self.assertEqual(invert, not key.matches_char(c))
74 for c in no_match: 74 for c in no_match:
75 self.assertEqual(invert, key.matches_char(c)) 75 self.assertEqual(invert, key.matches_char(c))
76 76
77 def test_self_defined_classes(self): 77 def test_self_defined_classes(self):
78 encoding = self.__encoding 78 encoding = self.__encoding
79 graph = RegexParser.parse("[a-z]") 79 graph = RegexParser.parse("[a-z]")
80 classes = { 80 classes = {
81 'self_defined' : TransitionKey.character_class(encoding, graph, {})} 81 'self_defined' : TransitionKey.character_class(encoding, graph, {})}
82 graph = RegexParser.parse("[^:self_defined:]") 82 graph = RegexParser.parse("[^:self_defined:]")
83 key = TransitionKey.character_class(encoding, graph, classes) 83 key = TransitionKey.character_class(encoding, graph, classes)
84 self.assertTrue(key.matches_char('A')) 84 self.assertTrue(key.matches_char('A'))
85 85
86 def test_disjoint_keys(self): 86 def test_disjoint_keys(self):
87 encoding = self.__encoding 87 encoding = self.__encoding
88 key1 = TransitionKey(encoding, [(1, 10)]) 88 key1 = TransitionKey(encoding, [(1, 10)])
89 key2 = TransitionKey(encoding, [(5, 15)]) 89 key2 = TransitionKey(encoding, [(5, 15)])
90 disjoint_set = TransitionKey.disjoint_keys(encoding, set([key1, key2])) 90 disjoint_set = TransitionKey.disjoint_keys(encoding, set([key1, key2]))
91 self.assertTrue(TransitionKey(encoding, [(1, 4)]) in disjoint_set) 91 self.assertTrue(TransitionKey(encoding, [(1, 4)]) in disjoint_set)
92 self.assertTrue(TransitionKey(encoding, [(5, 10)]) in disjoint_set) 92 self.assertTrue(TransitionKey(encoding, [(5, 10)]) in disjoint_set)
93 self.assertTrue(TransitionKey(encoding, [(11, 15)]) in disjoint_set) 93 self.assertTrue(TransitionKey(encoding, [(11, 15)]) in disjoint_set)
OLDNEW
« no previous file with comments | « tools/lexer_generator/term_test.py ('k') | tools/lexer_generator/transition_keys.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698