コード例 #1
0
 def test_match1(self):
     p = pattern.ParameterizedPattern(tokenize("foo $var bar"))
     rest, s, v = p.match(tokenize("foo buzz blarg bar"))
     self.assertEqual(0, len(rest))
     self.assertTrue(s)
     self.assertEqual(list(tokenize("buzz blarg")),
                      v[list(tokenize("$var"))[0]])
コード例 #2
0
 def test_match2(self):
     m = nfa.NFA(tokenize("this is $variable and that is $variable2"))
     ret = m.match(
         tokenize("this is madness really and that is not sparta for real"))
     self.assertIsNotNone(ret)
     self.assertEqual(list(tokenize("madness really")),
                      ret[list(tokenize("$variable"))[0]])
     self.assertEqual(list(tokenize("not sparta for real")),
                      ret[list(tokenize("$variable2"))[0]])
コード例 #3
0
 def test_init(self):
     nfa.NFA(tokenize("no wildcards"))
コード例 #4
0
 def test_one_any(self):
     m = nfa.NFA(tokenize("$any"))
     self.assertEqual(
         list(tokenize("foo foo foo")),
         m.match(tokenize("foo foo foo"))[tuple(tokenize("$any"))[0]])
コード例 #5
0
 def test_nomatch(self):
     m = nfa.NFA(tokenize("this $variable"))
     self.assertIsNone(m.match(tokenize("that is wrong")))
     self.assertIsNone(m.match(tokenize("this")))
     self.assertIsNone(m.match(tokenize("")))
コード例 #6
0
 def test_match4(self):
     m = nfa.NFA(tokenize("just some literals"))
     self.assertIsNotNone(m.match(tokenize("just some literals")))
コード例 #7
0
 def test_match1(self):
     m = nfa.NFA(tokenize("something $variable"))
     ret = m.match(tokenize("something or other"))
     result = ret[list(tokenize("$variable"))[0]]
     self.assertEqual(list(tokenize("or other")), result)
コード例 #8
0
 def test_init_with_variables2(self):
     nfa.NFA(tokenize("foo $var bar"))
コード例 #9
0
 def test_init_with_variables(self):
     nfa.NFA(tokenize("something $variable"))
コード例 #10
0
 def test_init(self):
     pattern.ParameterizedPattern(tokenize("foo $var bar"))