More regex tests

This commit is contained in:
Robin Jadoul 2016-05-30 16:57:46 +02:00
parent a1dfaf91d5
commit 41c48f50a1
1 changed files with 49 additions and 7 deletions

View File

@ -5,8 +5,48 @@ REFERENCE_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), "tests"
REGEXES_DATA = [ # (regexes, should be accepted)
([r"[a-zA-Z0-9]*"], True),
([r"[a-dD-F9-0]*"], True),
([r"a", r"a|b"], True),
([r"a|b", r"a"], True),
([r"[[]", r"[]]", r"[]-[]", r"[][-]"], True),
([r"[^^]", r"[^]-[]", r"[^][-]"], True),
([r"[^^]", r"[^]-[]", r"[^][-]"], True),
([r"[ ^]", r"[ ^-X ]", r"[]-^]"], True),
([r"[^-X]", r"[^][]"], True),
([r"[-]", r"[]-]"], True),
([r"[^-]", "[^]]", r"[^-]", r"[^-^]"], True),
([r"[^--]", r"[--]"], True),
([r"[^]"], False),
([r"[]"], False),
([r"\r", r"\n", r"\f", r"\v", r"\a", r"\t", r"\b", r"\s", r" "], True),
([r"\\", r"\*", r"\+", r"\|", r"\(", r"\)", r"\[", r"\[", r"\?", r"\."], True),
([r".", r"a*", r"a+", r"a?", r"(ab)*", r"a|b"], True),
([r"(a|b)*", r"(a|b)+", r"a**", r"a??", r"(ab)?"], True),
([r"("], False),
([r")"], False),
([r"["], False),
([r"]"], False),
([r"(test(a)qwerty"], False),
([r"test(a)qwerty)"], False),
([r"ab|"], False),
([r"|ab"], False),
([r"ab(c|)de"], False),
([r"ab(|c)de"], False),
([r""], False),
([r"()"], False),
([r"(?)"], False),
([r"((ab)c()de)"], False),
([r"|"], False),
([r"(|)"], False),
([r"?"], False),
([r"*"], False),
([r"(*)"], False),
([r"+"], False),
([r"(+)"], False),
]
EXAMPLE_TESTS = { #Mapping from test name to executable and number of available test input files
@ -16,19 +56,21 @@ EXAMPLE_TESTS = { #Mapping from test name to executable and number of availabl
def make_pipeline_test(regexes, should_accept, idx):
def test(self):
p = subprocess.Popen([os.path.join(args.builddir, "src", "Lexesis-test"), "test_%s" % idx, data_dir], stdin=subprocess.PIPE)
p.communicate(bytes("\n".join(regexes), "utf-8"))
if idx == 21:
print(regexes)
p = subprocess.Popen([os.path.join(args.builddir, "src", "Lexesis-test"), "test_%s" % idx, data_dir], stdin=subprocess.PIPE, stderr=subprocess.DEVNULL)
p.communicate(bytes("\n".join(regexes) + "\n", "utf-8"))
if should_accept:
self.assertEqual(0, p.returncode)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.re" % idx), os.path.join(data_dir, "test_%s.re" % idx)), "The regex for testcase %s is incorrect" % idx)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.enfa" % idx), os.path.join(data_dir, "test_%s.enfa" % idx)), "The eNFA for testcase %s is incorrect" % idx)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.mssc" % idx), os.path.join(data_dir, "test_%s.mssc" % idx)), "The mssc'd DFA for testcase %s is incorrect" % idx)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.min" % idx), os.path.join(data_dir, "test_%s.min" % idx)), "The minimized DFA for testcase %s is incorrect" % idx)
else:
self.assertNotEqual(0, p.returncode)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.re" % idx), os.path.join(data_dir, "test_%s.re" % idx)), "The regex for testcase %s is incorrect" % idx)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.enfa" % idx), os.path.join(data_dir, "test_%s.enfa" % idx)), "The eNFA for testcase %s is incorrect" % idx)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.mssc" % idx), os.path.join(data_dir, "test_%s.mssc" % idx)), "The mssc'd DFA for testcase %s is incorrect" % idx)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.min" % idx), os.path.join(data_dir, "test_%s.min" % idx)), "The minimized DFA for testcase %s is incorrect" % idx)
return test
def make_functional_test(name, prog, idx):