Пример #1
0
 def test_charclass_parsing(self):
     r = Regex.get_parse_tree(r"[ a]")
     l = list(find_all(r))[1:]  # skip root
     print("\n".join(fmttree(r)))
     self.assertEqual(3, len(l))
     self.assertEqual(r" ", l[1].data)
     self.assertEqual(r"a", l[2].data)
Пример #2
0
 def test_escaped_space_parsing(self):
     r = Regex.get_parse_tree(r"\ a")
     l = list(find_all(r))[1:]  # skip root
     print("\n".join(fmttree(r)))
     self.assertEqual(2, len(l))
     self.assertEqual(r"\ ", l[0].data)
     self.assertEqual(Other.Suspicious, l[0].type)
Пример #3
0
 def test_repetition_curly2(self):
     r = Regex.get_parse_tree(r"x{2,5}")
     l = list(find_all(r))[1:]  # skip root
     self.assertEqual(2, len(l))
     # l[0] is Repetition, l[1] is Literal(x)
     self.assertEqual(2, l[0].min)
     self.assertEqual(5, l[0].max)
     self.assertEqual(True, l[0].greedy)
Пример #4
0
 def test_repetition_curly1(self):
     r = Regex.get_parse_tree(r"x{5,5}?")
     print("\n".join(fmttree(r)))
     l = list(find_all(r))[1:]  # skip root
     self.assertEqual(2, len(l))
     # l[0] is Repetition, l[1] is Literal(x)
     self.assertEqual(5, l[0].min)
     self.assertEqual(5, l[0].max)
     self.assertEqual(False, l[0].greedy)
Пример #5
0
 def test_basic_verbose_parsing(self):
     r = Regex.get_parse_tree(r"""(?x)  a   b # comment
                     c
                     d""")
     l = list(find_all(r))[1:]  # skip root
     print("\n".join(fmttree(r)))
     self.assertEqual(5, len(l))
     self.assertEqual((4, 6), (l[1].parsed_start, l[1].start))
     self.assertEqual("d", l[-1].data)
     self.assertEqual((7, 72), (l[-1].parsed_start, l[-1].start))
Пример #6
0
 def test_complex_charclass(self):
     r = Regex.get_parse_tree(r"[]\[:_@\".{}()|;,]")
     l = list(find_all(r))[1:]  # skip root
     print("\n".join(fmttree(r)))
     self.assertEqual(15, len(l))
Пример #7
0
 def test_width(self):
     r = Regex.get_parse_tree(r"\s(?#foo)\b")
     l = list(find_all(r))[1:]  # skip root
     self.assertEqual([True, False, False], [width(i.type) for i in l])