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

Unified Diff: tools/lexer_generator/automata_test.py

Issue 54303002: Experimental parser: some unit tests (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 | « no previous file | tools/lexer_generator/dfa.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/automata_test.py
diff --git a/tools/testrunner/local/junit_output.py b/tools/lexer_generator/automata_test.py
similarity index 57%
copy from tools/testrunner/local/junit_output.py
copy to tools/lexer_generator/automata_test.py
index 437adb178931f82364aa87e66315231b7b57a56d..42346a9100d0e3c8facf7b569701e030288b1e49 100644
--- a/tools/testrunner/local/junit_output.py
+++ b/tools/lexer_generator/automata_test.py
@@ -25,25 +25,41 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+import unittest
+from regex_parser import RegexParser
+from nfa import NfaBuilder
+from dfa import Dfa
-import xml.etree.ElementTree as xml
+def build_automata(string):
+ parser = RegexParser()
+ parser.build()
+ graph = parser.parse(string)
+ nfa = NfaBuilder().nfa(graph)
+ (start_name, dfa_nodes, end_nodes) = nfa.compute_dfa()
+ dfa = Dfa(start_name, dfa_nodes, end_nodes)
+ return (nfa, dfa)
+class AutomataTestCase(unittest.TestCase):
-class JUnitTestOutput:
- def __init__(self, test_suite_name):
- self.root = xml.Element("testsuite")
- self.root.attrib["name"] = test_suite_name
+ # (pattern, should match, shouldn't match)
+ __test_data = [
+ ("a", ["a"], ["b"]),
+ ("ab", ["ab"], ["bb"]),
+ ("a+b", ["ab", "aab", "aaab"], ["a", "b"]),
+ ("a?b", ["ab", "b"], ["a", "c"]),
+ ("a*b", ["ab", "aaab", "b"], ["a", "c"]),
+ ("a|b", ["a", "b"], ["ab", "c"]),
+ ]
- def HasRunTest(self, test_name, test_duration, test_failure):
- testCaseElement = xml.Element("testcase")
- testCaseElement.attrib["name"] = " ".join(test_name)
- testCaseElement.attrib["time"] = str(round(test_duration, 3))
- if len(test_failure):
- failureElement = xml.Element("failure")
- failureElement.text = test_failure
- testCaseElement.append(failureElement)
- self.root.append(testCaseElement)
-
- def FinishAndWrite(self, file):
- xml.ElementTree(self.root).write(file, "UTF-8")
+ def test_matches(self):
+ for (regex, matches, not_matches) in AutomataTestCase.__test_data:
+ (nfa, dfa) = build_automata(regex)
+ for string in matches:
+ self.assertTrue(nfa.matches(string))
+ self.assertTrue(dfa.matches(string))
+ for string in not_matches:
+ self.assertFalse(nfa.matches(string))
+ self.assertFalse(dfa.matches(string))
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « no previous file | tools/lexer_generator/dfa.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698