示例#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)")