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

Unified Diff: tools/lexer_generator/transition_key_test.py

Issue 54773002: Experimental parser: key inversion (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/lexer_generator/regex_parser.py ('k') | tools/lexer_generator/transition_keys.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/transition_key_test.py
diff --git a/tools/lexer_generator/transition_key_test.py b/tools/lexer_generator/transition_key_test.py
index 00863bf11dd3e8455dae81c3c4e637723b421704..ad60f00e7ae35f64ec9509873140e06145a4b05f 100644
--- a/tools/lexer_generator/transition_key_test.py
+++ b/tools/lexer_generator/transition_key_test.py
@@ -27,6 +27,7 @@
import unittest
from transition_keys import TransitionKey
+from regex_parser import RegexParser
class TransitionKeyTestCase(unittest.TestCase):
@@ -44,5 +45,28 @@ class TransitionKeyTestCase(unittest.TestCase):
for (left, right) in self.__equal_pairs:
self.assertEqual(hash(left), hash(right))
+ def test_classes(self):
+ # class regex, should match, should not match
+ data = [
+ ("1-2", "12", "ab"),
+ ("a-zA-Z", "abyzABYZ" , "123"),
+ ("a-zA-Z0g" , "abyzABYZ0" , "123"),
+ ]
+ for (string, match, no_match) in data:
+ for invert in [False, True]:
+ if invert:
+ regex = "[^%s]" % string
+ token = "NOT_CLASS"
+ else:
+ regex = "[%s]" % string
+ token = "CLASS"
+ graph = RegexParser.parse(regex)
+ assert graph[0] == token
+ key = TransitionKey.character_class(invert, graph[1])
+ for c in match:
+ self.assertEqual(invert, not key.matches_char(c))
+ for c in no_match:
+ self.assertEqual(invert, key.matches_char(c))
+
if __name__ == '__main__':
unittest.main()
« 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