Beispiel #1
0
 def test_intersect_escaped_match(self):
     tests = [("\\\\", "?"), ("\\\\", "*"), ("\\\\a", "??"), ("\\\\a", "*"),
              ("\\?", "?"), ("\\*", "?"), ("?", "\\*"), ("?", "\\?"),
              ("*", "\\*"), ("*", "\\?"), ("\\*", "*"), ("\\?", "*"),
              ("\\?", "\\?"), ("\\*", "\\*"), ("\\a", "a"), ("a", "\\a")]
     for a, b in tests:
         match = intersect(a, b)
         self.assertTrue(match)
Beispiel #2
0
 def test_intersect_nonmatch(self):
     tests = [("one", "two"), ("one", "oneone"), ("oneone", "one"),
              ("prefix*", "literal"), ("literal", "prefix*"),
              ("*suffix", "literal"), ("literal", "*suffix"),
              ("*two*", "onethree"), ("onethree", "*two*"),
              ("*a*b*c*d*", "a1b23d4"), ("a1b23d4", "*a*b*c*d*"),
              ("prefix*", "literalprefix*"), ("literalprefix*", "prefix*"),
              ("*suffix", "*suffixliteral"), ("*suffixliteral", "*suffix"),
              ("one*three", "three*two*one"),
              ("three*two*one", "one*three"), ("?*b*?", "bcb"),
              ("bcb", "?*b*?"), ("?", ""), ("", "?")]
     for a, b in tests:
         match = intersect(a, b)
         self.assertFalse(match)
Beispiel #3
0
 def test_intersect_match(self):
     tests = [("", "", []), ("*", "", [("*", "")]), ("", "*", []),
              ("?", "?", [("?", "?")]), ("?", "a", [("?", "a")]),
              ("a", "?", []), ("?b?", "abc", [("?", "a"), ("?", "c")]),
              ("abc", "?b?", []), ("a?c", "abc", [("?", "b")]),
              ("abc", "a?c", []), ("*", "literal", [("*", "literal")]),
              ("literal", "*", []),
              ("prefix*", "prefixliteral", [("*", "literal")]),
              ("prefixliteral", "prefix*", []),
              ("*suffix", "literalsuffix", [("*", "literal")]),
              ("literalsuffix", "*suffix", []), ("*", "*", [("*", "*")]),
              ("prefix*", "*", [("*", "*")]),
              ("*", "prefix*", [("*", "prefix*")]),
              ("*suffix", "*", [("*", "*")]),
              ("*", "*suffix", [("*", "*suffix")]),
              ("prefix*", "prefixliteral*", [("*", "literal*")]),
              ("prefixliteral*", "prefix*", [("*", "*")]),
              ("*suffix", "*literalsuffix", [("*", "*literal")]),
              ("*literalsuffix", "*suffix", [("*", "*")]),
              ("*suffix", "*literalsufsuffix", [("*", "*literalsuf")]),
              ("*literalsufsuffix", "*suffix", [("*", "*")]),
              ("prefix*suffix", "prefix*literal*suffix", [("*", "*literal*")
                                                          ]),
              ("prefix*literal*suffix", "prefix*suffix", [("*", "*"),
                                                          ("*", "*")]),
              ("a*b*c", "a*b*d*b*c", [("*", "*"), ("*", "*d*b*")]),
              ("a*b*d*b*c", "a*b*c", [("*", "*"), ("*", "*"), ("*", "*"),
                                      ("*", "*")]),
              ("abc*", "*cde", [("*", "de")]),
              ("*cde", "abc*", [("*", "ab")]),
              ("?*b*?", "cbc", [("?", "c"), ("*", ""), ("*", ""),
                                ("?", "c")]), ("cbc", "?*b*?", []),
              ("?*b*?", "acbca", [("?", "a"), ("*", "c"), ("*", "c"),
                                  ("?", "a")]), ("acbca", "?*b*?", []),
              ("*?*", "a", [("*", ""), ("?", "a"), ("*", "")]),
              ("a", "*?*", []), ("stream/*", "*", [("*", "*")]),
              ("*ba", "*b*", [("*", "*")])]
     for a, b, c in tests:
         match = intersect(a, b)
         self.assertTrue(match)
         if match.grouplist != c:
             self.assertEqual(match.grouplist, c)
Beispiel #4
0
 def test_intersect_match_getitem_indexerror(self):
     match = intersect("?", "a")
     with self.assertRaises(IndexError):
         match[5]
Beispiel #5
0
 def test_intersect_match_getitem(self):
     match = intersect("?*b*?", "acbca")
     self.assertEqual(match[1], "c")
Beispiel #6
0
    def test_intersect_match_groups(self):
        match = intersect("?*b*?", "acbca")
        self.assertEqual(match.groups, ("a", "c", "c", "a"))

        match = intersect("abcd", "abcd")
        self.assertEqual(match.groups, ())
Beispiel #7
0
 def test_intersect_escaped_valueerror(self):
     with self.assertRaises(ValueError):
         intersect("\\", "a")
Beispiel #8
0
 def test_intersect_escaped_nomatch(self):
     tests = [("\\?", "?a"), ("\\?", "a"), ("\\*", "?a"), ("\\*", "a"),
              ("\\*", ""), ("\\\\", "??")]
     for a, b in tests:
         match = intersect(a, b)
         self.assertFalse(match)