Beispiel #1
0
 def test_difficult_star(self: 'TestRegexMatch') -> None:
     """Correct on difficult case for star (1|(1.2))*?
     Almost-correct implementation of * will fail this test, in particular
     will not get accept enough strings."""
     r = S(B(L1, D(L1, L2)))
     yes = ["11212", "12121", "112112"]
     no = ["1221", "11221"]
     for s in yes:
         self.assertTrue(regex_match(r, s),
                         "Rejects valid match: {}".format((r, s)))
     for s in no:
         self.assertFalse(regex_match(r, s),
                          "Accepts invalid match: {}".format((r, s)))
Beispiel #2
0
 def test_dot_okay(self: 'TestRegexMatch') -> None:
     """Correctly matches dotted regexes?"""
     dot_list = [(D(L1, LE), '1'), (D(LE, L2), '2'), (D(L1, L1), '11'),
                 (D(L0, L2), '02')]
     for t in dot_list:
         self.assertTrue(regex_match(t[0], t[1]),
                         "Rejects valid match: {}".format(t))
Beispiel #3
0
 def test_star_fail(self: 'TestRegexMatch') -> None:
     """Correctly rejects near-stars?"""
     nearly_star_list = [(S(L1), '1 1'), (S(L2), '22212'),
                         (S(L0), '0000 0'), (S(L0), '3')]
     for t in nearly_star_list:
         self.assertFalse(regex_match(t[0], t[1]),
                          "Accepts invalid match: {}".format(t))
Beispiel #4
0
 def test_bar_fail(self: 'TestRegexMatch') -> None:
     """Correctly rejects near-bars?"""
     nearly_bar_list = [(B(L1, L2), '12'), (B(L1, L2), '0'), (B(L1,
                                                                L2), '')]
     for t in nearly_bar_list:
         self.assertFalse(regex_match(t[0], t[1]),
                          "Accepts invalid match: {}".format(t))
Beispiel #5
0
 def test_bar_star_fail(self: 'TestRegexMatch') -> None:
     """Correctly rejects near bar-stars?"""
     near_bar_star_list = [(B(L0, S(L1)), '(0|1*)'), (B(L0, S(L1)), '01'),
                           (S(B(L0, L1)), '(0|1)*'), (S(B(L0, L1)), '00 1')]
     for t in near_bar_star_list:
         self.assertFalse(regex_match(t[0], t[1]),
                          "Accepts invalid match: {}".format(t))
Beispiel #6
0
 def test_dot_star_fail(self: 'TestRegexMatch') -> None:
     """Correctly rejects near dot-stars?"""
     near_dot_star_list = [(D(L0, S(L1)), '(0.1*)'), (D(L0, S(L1)), '0101'),
                           (S(D(L1, L1)), '111'), (S(D(L1, L0)), '1100')]
     for t in near_dot_star_list:
         self.assertFalse(regex_match(t[0], t[1]),
                          "Accepts invalid match: {}".format(t))
Beispiel #7
0
 def test_edge_empty_ok(self: 'TestRegexMatch') -> None:
     """Correctly matches various matches of empty string?"""
     empty_string_list = [(D(LE, LE), ''), (B(L0, LE), ''), (S(L2), ''),
                          (S(LE), '')]
     for t in empty_string_list:
         self.assertTrue(regex_match(t[0], t[1]),
                         "Rejects valid match: {}".format(t))
Beispiel #8
0
 def test_leaf_fail(self: 'TestRegexMatch') -> None:
     """Correct rejects near-leaves?"""
     nearly_leaf_list = [(LE, 'e'), (L0, '(0)'), (LE, '()'), (L1, '11'),
                         (L1, '3')]
     for t in nearly_leaf_list:
         self.assertFalse(regex_match(t[0], t[1]),
                          "Accepts invalid match: {}".format(t))
Beispiel #9
0
 def test_dot_fail(self: 'TestRegexMatch') -> None:
     """Correctly rejects near-dots?"""
     nearly_dot_list = [(D(L1, L0), '1'), (D(L1, L0), '102'),
                        (D(L1, L0), '1.0'), (D(L1, L2), '(12)'),
                        (D(L1, L2), '(1.2)')]
     for t in nearly_dot_list:
         self.assertFalse(regex_match(t[0], t[1]),
                          "Accepts invalid match: {}".format(t))
Beispiel #10
0
 def test_bar_star_ok(self: 'TestRegexMatch') -> None:
     """Correctly matches bar-star regexes?"""
     bar_star_list = [(B(S(L1), S(L0)), '000'), (S(B(L2,
                                                     L1)), '11212212212'),
                      (S(B(L1, B(L0, L2))), '1002221102201')]
     for t in bar_star_list:
         self.assertTrue(regex_match(t[0], t[1]),
                         "Rejects valid match: {}".format(t))
Beispiel #11
0
 def test_dot_bar_ok(self: 'TestRegexMatch') -> None:
     """Correctly matches dot-bar regexes?"""
     dot_bar_list = [(D(B(L0, L1), B(L2, L0)), '12'),
                     (B(D(L0, L1), D(L2, L0)), '20'),
                     (D(B(L0, L1), D(L2, L1)), '121'),
                     (B(D(L0, L1), B(L2, L1)), '01')]
     for t in dot_bar_list:
         self.assertTrue(regex_match(t[0], t[1]),
                         "Rejects valid match: {}".format(t))
Beispiel #12
0
 def test_dot_bar_fail(self: 'TestRegexMatch') -> None:
     """Correctly rejects near dot-bars?"""
     nearly_dot_bar_list = [(D(B(L0, L1), B(L2, L0)), '012'),
                            (B(D(L0, L1), D(L2, L0)), '02'),
                            (D(B(L0, L1), D(L2, L1)), '0121'),
                            (B(D(L0, L1), B(L2, L1)), '0121')]
     for t in nearly_dot_bar_list:
         self.assertFalse(regex_match(t[0], t[1]),
                          "Accepts invalid match: {}".format(t))
Beispiel #13
0
 def test_bar_star_dot_ok(self: 'TestRegexMatch') -> None:
     """Correctly matches bar-star-dot regexes?"""
     bar_star_dot_list = [(B(S(L2), D(L1, L0)), '10'),
                          (B(S(L2), D(L1, L0)), '222'),
                          (D(B(L0, L2), S(L1)), '0111'),
                          (S(D(B(L0, L2), S(L1))), '0121210121'),
                          (S(S(L2)), '22222')]
     for t in bar_star_dot_list:
         self.assertTrue(regex_match(t[0], t[1]),
                         "Rejects valid match: {}".format(t))
Beispiel #14
0
 def test_bar_star_dot_fail(self: 'TestRegexMatch') -> None:
     """Correctly rejects near bar-star-dots?"""
     near_bar_star_dot_list = [(B(S(L2), D(L1, L0)), '210'),
                               (B(S(L2), D(L1, L0)), '1'),
                               (D(B(L0, L2), S(L1)), '02111'),
                               (S(D(B(L0, L2), S(L1))), '102102'),
                               (S(S(L2)), '2 2222')]
     for t in near_bar_star_dot_list:
         self.assertFalse(regex_match(t[0], t[1]),
                          "Accepts invalid match: {}".format(t))
Beispiel #15
0
 def test_dot_star_ok(self: 'TestRegexMatch') -> None:
     """Correctly matches dot-star regexes?"""
     dot_star_list = [(D(S(L1), S(L2)), '112'), (D(S(L1), S(L2)), '122'),
                      (D(S(L1), S(L2)), '2222'), (D(S(L1), S(L2)), '111'),
                      (S(D(L1, L0)), '101010'),
                      (D(L1, S(D(L2, L0))), '1202020'),
                      (D(L1, S(D(L2, L0))), '1'), (S(D(L1,
                                                       S(L0))), '100110')]
     for t in dot_star_list:
         self.assertTrue(regex_match(t[0], t[1]),
                         "Rejects valid match: {}".format(t))
Beispiel #16
0
 def test_star_okay(self: 'TestRegexMatch') -> None:
     """Correctly matches starred regexes?"""
     star_list = [(S(L1), '1'), (S(L2), '222222')]
     for t in star_list:
         self.assertTrue(regex_match(t[0], t[1]),
                         "Rejects valid match: {}".format(t))
Beispiel #17
0
 def test_bar_okay(self: 'TestRegexMatch') -> None:
     """Correctly matches barred regexes?"""
     bar_list = [(B(L1, LE), '1'), (B(LE, L2), '2'), (B(L1, L1), '1')]
     for t in bar_list:
         self.assertTrue(regex_match(t[0], t[1]),
                         "Rejects valid match: {}".format(t))
Beispiel #18
0
 def test_leaf_ok(self: 'TestRegexMatch') -> None:
     """Correctly matches leaf regexes?"""
     leaf_list = [(LE, ''), (L0, '0'), (L1, '1'), (L2, '2')]
     for t in leaf_list:
         self.assertTrue(regex_match(t[0], t[1]),
                         "Rejects valid match: {}".format(t))