Пример #1
0
 def test_range_in_brackets(self):
     regex = PythonRegex("a[a-z]")
     self.assertTrue(regex.accepts(["a", "a"]))
     self.assertTrue(regex.accepts(["a", "c"]))
     self.assertTrue(regex.accepts(["a", "g"]))
     self.assertTrue(regex.accepts(["a", "z"]))
     self.assertFalse(regex.accepts(["a", "b", "c"]))
     self.assertFalse(regex.accepts(["a", "A"]))
Пример #2
0
 def test_range_in_brackets_trap(self):
     regex = PythonRegex("a[a-e-z]")
     self.assertTrue(regex.accepts(["a", "a"]))
     self.assertTrue(regex.accepts(["a", "c"]))
     self.assertTrue(regex.accepts(["a", "z"]))
     self.assertTrue(regex.accepts(["a", "-"]))
     self.assertFalse(regex.accepts(["a", "y"]))
     self.assertFalse(regex.accepts(["a", "f"]))
Пример #3
0
 def test_dot(self):
     regex = PythonRegex("a.")
     self.assertTrue(regex.accepts(["a", "b"]))
     self.assertTrue(regex.accepts(["a", "?"]))
     self.assertFalse(regex.accepts(["a", "\n"]))
     self.assertFalse(regex.accepts(["a"]))
     self.assertTrue(regex.accepts(["a", "|"]))
     self.assertTrue(regex.accepts(["a", "("]))
     self.assertTrue(regex.accepts(["a", ")"]))
     self.assertTrue(regex.accepts(["a", "."]))
     self.assertTrue(regex.accepts(["a", "*"]))
     self.assertTrue(regex.accepts(["a", "+"]))
     self.assertTrue(regex.accepts(["a", "$"]))
Пример #4
0
 def test_special_in_brackets_kleene_star(self):
     regex = PythonRegex(r"a[a*]")
     self.assertTrue(regex.accepts(["a", "a"]))
     self.assertTrue(regex.accepts(["a", "*"]))
     self.assertFalse(regex.accepts(["a", "a", "a"]))
Пример #5
0
 def test_shortcut_word(self):
     regex = PythonRegex(r"a\w")
     self.assertTrue(regex.accepts(["a", "0"]))
     self.assertTrue(regex.accepts(["a", "_"]))
     self.assertTrue(regex.accepts(["a", "A"]))
     self.assertTrue(regex.accepts(["a", "f"]))
Пример #6
0
 def test_escape_backslash_plus(self):
     regex = PythonRegex(r"a\\+")
     self.assertTrue(regex.accepts(["a", "\\", "\\"]))
Пример #7
0
 def test_escape_closing_bracket(self):
     regex = PythonRegex(r"a\]")
     self.assertTrue(regex.accepts(["a", "]"]))
Пример #8
0
 def test_space(self):
     regex = PythonRegex(" ")
     self.assertTrue(regex.accepts([" "]))
Пример #9
0
 def test_with_parenthesis_optional(self):
     regex = PythonRegex("a(bb|c)?")
     self.assertTrue(regex.accepts(["a"]))
     self.assertTrue(regex.accepts(["a", "b", "b"]))
     self.assertTrue(regex.accepts(["a", "c"]))
     self.assertFalse(regex.accepts(["a", "b"]))
Пример #10
0
 def test_escape_kleene_star(self):
     regex = PythonRegex(r"ab\*")
     self.assertTrue(regex.accepts(["a", "b", "*"]))
Пример #11
0
 def test_plus(self):
     regex = PythonRegex("a+")
     self.assertFalse(regex.accepts([]))
     self.assertTrue(regex.accepts(["a"]))
     self.assertTrue(regex.accepts(["a", "a"]))
Пример #12
0
 def test_dot_spaces(self):
     regex = PythonRegex("a.")
     self.assertTrue(regex.accepts(["a", " "]))
     self.assertTrue(regex.accepts(["a", "\t"]))
     self.assertTrue(regex.accepts(["a", "\v"]))
     self.assertTrue(regex.accepts(["a", "\r"]))
Пример #13
0
 def test_special_in_brackets_closing_parenthesis(self):
     regex = PythonRegex(r"a[a)]")
     self.assertTrue(regex.accepts(["a", "a"]))
     self.assertTrue(regex.accepts(["a", ")"]))
Пример #14
0
 def test_range_in_brackets_trap2_bis(self):
     regex = PythonRegex(re.compile("[a-e-g-z]*"))
     self.assertTrue(regex.accepts(["a", "-", "y"]))
Пример #15
0
 def test_with_brackets(self):
     regex = PythonRegex("a[bc]")
     self.assertTrue(regex.accepts(["a", "b"]))
     self.assertTrue(regex.accepts(["a", "c"]))
     self.assertFalse(regex.accepts(["a", "b", "c"]))
     self.assertFalse(regex.accepts(["a", "a"]))
Пример #16
0
 def test_escape_dash_in_brackets(self):
     regex = PythonRegex(r"a[a\-]")
     self.assertTrue(regex.accepts(["a", "a"]))
     self.assertTrue(regex.accepts(["a", "-"]))
Пример #17
0
 def test_escape_backslash_question_mark(self):
     regex = PythonRegex(r"a\\?")
     self.assertTrue(regex.accepts(["a"]))
     self.assertTrue(regex.accepts(["a", "\\"]))
     self.assertFalse(regex.accepts(["a", "\\", "?"]))
     self.assertFalse(regex.accepts(["a", "\\?"]))
Пример #18
0
 def test_escape_backslash_closing_bracket(self):
     regex = PythonRegex(r"a[ab\\]")
     self.assertTrue(regex.accepts(["a", "a"]))
     self.assertTrue(regex.accepts(["a", "b"]))
     self.assertTrue(regex.accepts(["a", "\\"]))
Пример #19
0
 def test_escape_backslash_opening_bracket(self):
     regex = PythonRegex(r"a\\[ab]")
     self.assertTrue(regex.accepts(["a", "\\", "a"]))
     self.assertTrue(regex.accepts(["a", "\\", "b"]))
Пример #20
0
 def test_parenthesis(self):
     regex = PythonRegex("((a)|(b))+")
     self.assertTrue(regex.accepts(["a", "b"]))
Пример #21
0
 def test_special_in_brackets_positive_closure(self):
     regex = PythonRegex(r"a[a+]")
     self.assertTrue(regex.accepts(["a", "a"]))
     self.assertTrue(regex.accepts(["a", "+"]))
     self.assertFalse(regex.accepts(["a", "a", "a"]))
Пример #22
0
 def test_special_in_brackets_optional(self):
     regex = PythonRegex(r"a[a?]")
     self.assertTrue(regex.accepts(["a", "a"]))
     self.assertTrue(regex.accepts(["a", "?"]))
     self.assertFalse(regex.accepts(["a"]))
Пример #23
0
 def test_shortcut_digits(self):
     regex = PythonRegex(r"a\d")
     self.assertTrue(regex.accepts(["a", "0"]))
     self.assertTrue(regex.accepts(["a", "1"]))
Пример #24
0
 def test_simple_optional(self):
     regex = PythonRegex("ab?")
     self.assertTrue(regex.accepts(["a"]))
     self.assertTrue(regex.accepts(["a", "b"]))
     self.assertFalse(regex.accepts(["a", "a"]))
Пример #25
0
 def test_shortcut_digits_in_brackets(self):
     regex = PythonRegex(r"a[\da]")
     self.assertTrue(regex.accepts(["a", "0"]))
     self.assertTrue(regex.accepts(["a", "1"]))
     self.assertTrue(regex.accepts(["a", "a"]))
Пример #26
0
 def test_escape_question_mark(self):
     regex = PythonRegex(r"ab\?")
     self.assertTrue(regex.accepts(["a", "b", "?"]))
Пример #27
0
 def test_shortcut_spaces(self):
     regex = PythonRegex(r"a\s")
     self.assertTrue(regex.accepts(["a", " "]))
     self.assertTrue(regex.accepts(["a", "\t"]))
Пример #28
0
 def test_escape_plus(self):
     regex = PythonRegex(r"ab\+")
     self.assertTrue(regex.accepts(["a", "b", "+"]))
     self.assertFalse(regex.accepts(["a", "b", "\\"]))
Пример #29
0
 def test_escape_opening_bracket(self):
     regex = PythonRegex(r"a\[")
     self.assertTrue(regex.accepts(["a", "["]))