Пример #1
0
 def test_grouping(self):
     a = get_regex_tree("((foo|bar)|baz)")
     self.failUnless(a.random() in [
         "foo",
         "bar",
         "baz",
         ])
Пример #2
0
 def test_url_regex(self):
     regex = r'(http|ssh)s?://[^\s\r\n]+'
     matcher = re.compile(regex)
     a = get_regex_tree(regex)
     for i in range(50):
         subject = a.random()
         if not matcher.match(subject):
             raise ValueError("'%s' isnt right!" % subject)
Пример #3
0
 def test_repetition(self):
     a = get_regex_tree("a+")
     self.failUnlessEqual(a.graph(), "Sq(Re(Ch))")
Пример #4
0
 def test_grouping_then_sequence(self):
     a = get_regex_tree("(foo|bar)baz")
     self.failUnless(a.random() in [
         "foobaz",
         "barbaz",
         ])
Пример #5
0
 def test_repetition(self):
     a = get_regex_tree("a?")
     self.failUnless(a.random() in [
         "",
         "a",
         ])
Пример #6
0
 def test_url_regex(self):
     a = get_regex_tree(r'(http|ssh)s?://[^\s\r\n]+')
     self.failUnlessEqual(a.graph(),
         "Sq(Al(Sq(Ch,Ch,Ch,Ch),Sq(Ch,Ch,Ch)),Re(Ch),Ch,Ch,Ch,Re(Cc^(Cc,Ch,Ch)))")
Пример #7
0
 def test_nested_grouping(self):
     a = get_regex_tree("((foo|bar)|baz)")
     self.failUnlessEqual(a.graph(), "Sq(Al(Sq(Al(Sq(Ch,Ch,Ch),Sq(Ch,Ch,Ch))),Sq(Ch,Ch,Ch)))")
Пример #8
0
 def test_multiple_grouping(self):
     a = get_regex_tree("(f|o|o|b|a|r)")
     self.failUnlessEqual(a.graph(), "Sq(Al(Sq(Ch),Sq(Ch),Sq(Ch),Sq(Ch),Sq(Ch),Sq(Ch)))")
Пример #9
0
 def test_grouping_repetition(self):
     a = get_regex_tree("(foo|bar){1,2}")
     self.failUnlessEqual(a.graph(), "Sq(Re(Al(Sq(Ch,Ch,Ch),Sq(Ch,Ch,Ch))))")
Пример #10
0
 def test_characters(self):
     a = get_regex_tree("foo")
     self.failUnlessEqual(a.graph(), "Sq(Ch,Ch,Ch)")