[pypy-commit] pypy pyparser-improvements-3: add at least a very minimal recognize test
cfbolz
pypy.commits at gmail.com
Sat Apr 14 05:57:15 EDT 2018
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: pyparser-improvements-3
Changeset: r94320:2b4152c6c930
Date: 2018-04-14 11:56 +0200
http://bitbucket.org/pypy/pypy/changeset/2b4152c6c930/
Log: add at least a very minimal recognize test
diff --git a/pypy/interpreter/pyparser/test/test_automata.py b/pypy/interpreter/pyparser/test/test_automata.py
--- a/pypy/interpreter/pyparser/test/test_automata.py
+++ b/pypy/interpreter/pyparser/test/test_automata.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.pyparser.automata import DFA, DEFAULT
+from pypy.interpreter.pyparser.automata import DFA, NonGreedyDFA, DEFAULT
def test_states():
d = DFA([{"\x00": 1}, {"\x01": 0}], [False, True])
@@ -10,3 +10,20 @@
assert d.states == "\x01\x00"
assert d.defaults == "\xff\x00"
assert d.max_char == 1
+
+def test_recognize():
+ d = DFA([{"a": 1}, {"b": 0}], [False, True])
+ assert d.recognize("ababab") == 5
+ assert d.recognize("c") == -1
+
+ d = DFA([{"a": 1}, {DEFAULT: 0}], [False, True])
+ assert d.recognize("a,a?ab") == 5
+ assert d.recognize("c") == -1
+
+ d = NonGreedyDFA([{"a": 1}, {"b": 0}], [False, True])
+ assert d.recognize("ababab") == 1
+ assert d.recognize("c") == -1
+
+ d = NonGreedyDFA([{"a": 1}, {DEFAULT: 0}], [False, True])
+ assert d.recognize("a,a?ab") == 1
+ assert d.recognize("c") == -1
More information about the pypy-commit
mailing list