示例#1
0
 def test_ofAny(self):
     regex = RegExpBuilder()
     regex.start()
     regex.exactly(3).ofAny()
     regex.end()
     regex = regex.getRegExp()
     
     self.assertTrue(regex.match("pqr") is not None)
示例#2
0
 def test_start(self):
     regex = RegExpBuilder()
     regex.start()
     regex.exactly(1).of("p")
     regex = regex.getRegExp()
 
     self.assertTrue(regex.match("p") is not None)
     self.assertTrue(regex.match("qp") is None)
示例#3
0
 def test_notFromClass(self):
     someLetters = ["p", "q", "r"]
     regex = RegExpBuilder()
     regex.start()
     regex.exactly(3).notFromClass(someLetters)
     regex.end()
     regex = regex.getRegExp()
     
     self.assertTrue(regex.match("lmn") is not None)
     self.assertTrue(regex.match("mnq") is None)
示例#4
0
 def test_ofGroup(self):
     regex = RegExpBuilder()
     regex.start()
     regex.exactly(3).of("p").asGroup()
     regex.exactly(1).of("q")
     regex.exactly(1).ofGroup(1)
     regex.end()
     regex = regex.getRegExp()
     
     self.assertTrue(regex.match("pppqppp") is not None)
示例#5
0
 def test_min(self):
     regex = RegExpBuilder()
     regex.start()
     regex.min(2).of("p")
     regex.end()
     regex = regex.getRegExp()
     
     self.assertTrue(regex.match("pp") is not None)
     self.assertTrue(regex.match("ppp") is not None)
     self.assertTrue(regex.match("ppppppp") is not None)
     self.assertTrue(regex.match("p") is None)
示例#6
0
 def test_like(self):
     pattern = lambda r: r.min(1).of("p").min(2).of("q")
     
     regex = RegExpBuilder()
     regex.start()
     regex.exactly(2).like(pattern)
     regex.end()
     regex = regex.getRegExp()
     
     self.assertTrue(regex.match("pqqpqq") is not None)
     self.assertTrue(regex.match("qppqpp") is None)
示例#7
0
 def test_eitherLike_orLike(self):
     regex = RegExpBuilder()
     regex.start()
     regex.eitherLike(lambda r: r.exactly(1).of("p"))
     regex.orLike(lambda r: r.exactly(2).of("q"))
     regex.end()
     regex = regex.getRegExp()
     
     self.assertTrue(regex.match("p") is not None)
     self.assertTrue(regex.match("qq") is not None)
     self.assertTrue(regex.match("pqq") is None)
     self.assertTrue(regex.match("qqp") is None)
示例#8
0
 def test_fromClass(self):
     someLetters = ["p", "q", "r"]
     regex = RegExpBuilder()
     regex.start()
     regex.exactly(3).fromClass(someLetters)
     regex.end()
     regex = regex.getRegExp()
     
     self.assertTrue(regex.match("ppp") is not None)
     self.assertTrue(regex.match("qqq") is not None)
     self.assertTrue(regex.match("ppq") is not None)
     self.assertTrue(regex.match("rqp") is not None)
     self.assertTrue(regex.match("pyy") is None)