예제 #1
0
 def test_module_level_functions(self):
     """
     Quick test of module-level functions.
     These are generally expected to call the compiled counterparts,
      so these tests do not check all aspects
     """
     assert_equal(cffi_re2.findall(r'a(b+)', "abbcdefabbbbca"), ["bb", "bbbb"])
     assert_equal(cffi_re2.sub(r'b+', '', 'abbcbbd'), 'acd')
     assert_is_not_none(cffi_re2.search(r'b+', 'abbcbbd'))
     assert_is_none(cffi_re2.match(r'b+', 'abbcbbd'))
     assert_is_not_none(cffi_re2.match(r'b+', 'bbbbb'))
예제 #2
0
 def test_module_level_functions(self):
     """
     Quick test of module-level functions.
     These are generally expected to call the compiled counterparts,
      so these tests do not check all aspects
     """
     assert_equal(cffi_re2.findall(r'a(b+)', "abbcdefabbbbca"),
                  ["bb", "bbbb"])
     assert_equal(cffi_re2.sub(r'b+', '', 'abbcbbd'), 'acd')
     assert_is_not_none(cffi_re2.search(r'b+', 'abbcbbd'))
     assert_is_none(cffi_re2.match(r'b+', 'abbcbbd'))
     assert_is_not_none(cffi_re2.match(r'b+', 'bbbbb'))
예제 #3
0
 def test_basic_match(self):
     # Search-type regex should NOT match full string
     robj = cffi_re2.compile(r'b+')
     assert_is_none(robj.match('abbcd'))
     # This regex only matches the left end
     robj = cffi_re2.compile(r'[abc]+$')
     assert_is_none(robj.match('abbcd'))
     # Full match regex should match
     robj = cffi_re2.compile(r'[abcd]+')
     assert_is_not_none(robj.match('abbcd'))
     # Regex match should be left-anchored, not both-anchored
     robj = cffi_re2.compile(r'a+')
     assert_is_not_none(robj.match('aaab'))
     assert_is_none(robj.match('baaab'))
예제 #4
0
 def test_basic_match(self):
     # Search-type regex should NOT match full string
     robj = cffi_re2.compile(r'b+')
     assert_is_none(robj.match('abbcd'))
     # This regex only matches the left end
     robj = cffi_re2.compile(r'[abc]+$')
     assert_is_none(robj.match('abbcd'))
     # Full match regex should match
     robj = cffi_re2.compile(r'[abcd]+')
     assert_is_not_none(robj.match('abbcd'))
     # Regex match should be left-anchored, not both-anchored
     robj = cffi_re2.compile(r'a+')
     assert_is_not_none(robj.match('aaab'))
     assert_is_none(robj.match('baaab'))
예제 #5
0
 def test_medium_complexity(self):
     """Check medium complexity regexes"""
     # Examples from github.com/ulikoehler/KATranslationCheck
     # 1
     rgx = cffi_re2.compile(r"\b[Ii]nto\b")
     assert_is_not_none(rgx.search("Into the darkness"))
     assert_is_not_none(rgx.search("I went into the darkness"))
     assert_is_none(rgx.search("abcde beintoaqe aqet"))
     # 2
     rgx = cffi_re2.compile(r"\d+\$\s*dollars?")
     assert_is_not_none(rgx.search("12$ dollars"))
     assert_is_not_none(rgx.match("12$ dollars"))
     assert_is_not_none(rgx.match("1$ dollar"))
     assert_is_not_none(rgx.match("1$  dollar"))
     assert_is_not_none(rgx.match("1$  dollars"))
예제 #6
0
 def test_basic_findall(self):
     robj = cffi_re2.compile(r'a(b+)')
     mo = robj.findall("abbcdefabbbbca")
     assert_is_not_none(mo)
     assert_equal(mo, ["bb", "bbbb"])
예제 #7
0
 def test_basic_groups(self):
     robj = cffi_re2.compile(r'a(b+)')
     mo = robj.search("abbc")
     assert_is_not_none(mo)
     assert_equal(mo.groups(), ("bb", ))
예제 #8
0
 def test_flag_ignorecase(self):
     rgx_ci = cffi_re2.compile(r'a(b+)$', flags=cffi_re2.IGNORECASE)
     rgx_cs = cffi_re2.compile(r'a(b+)$')
     # Check case sensitive
     assert_is_none(rgx_cs.match("AB"))
     assert_is_none(rgx_cs.match("Ab"))
     assert_is_none(rgx_cs.match("aB"))
     assert_is_none(rgx_cs.match("aBb"))
     assert_is_none(rgx_cs.match("abB"))
     assert_is_not_none(rgx_cs.match("ab"))
     assert_is_not_none(rgx_cs.match("abb"))
     # Check case insensitive
     assert_is_not_none(rgx_ci.match("AB"))
     assert_is_not_none(rgx_ci.match("Ab"))
     assert_is_not_none(rgx_ci.match("aB"))
     assert_is_not_none(rgx_ci.match("aBb"))
     assert_is_not_none(rgx_ci.match("abB"))
     assert_is_not_none(rgx_ci.match("ab"))
     assert_is_not_none(rgx_ci.match("abb"))
     # Official example
     assert_equal(
         cffi_re2.sub(r'\sAND\s',
                      ' & ',
                      'Baked Beans And Spam',
                      flags=cffi_re2.IGNORECASE), 'Baked Beans & Spam')
예제 #9
0
 def test_basic_search(self):
     robj = cffi_re2.compile(r'b+')
     assert_is_not_none(robj.search('abbcd'))
예제 #10
0
 def test_medium_complexity(self):
     """Check medium complexity regexes"""
     # Examples from github.com/ulikoehler/KATranslationCheck
     # 1
     rgx = cffi_re2.compile(r"\b[Ii]nto\b")
     assert_is_not_none(rgx.search("Into the darkness"))
     assert_is_not_none(rgx.search("I went into the darkness"))
     assert_is_none(rgx.search("abcde beintoaqe aqet"))
     # 2
     rgx = cffi_re2.compile(r"\d+\$\s*dollars?")
     assert_is_not_none(rgx.search("12$ dollars"))
     assert_is_not_none(rgx.match("12$ dollars"))
     assert_is_not_none(rgx.match("1$ dollar"))
     assert_is_not_none(rgx.match("1$  dollar"))
     assert_is_not_none(rgx.match("1$  dollars"))
예제 #11
0
 def test_basic_findall(self):
     robj = cffi_re2.compile(r'a(b+)')
     mo = robj.findall("abbcdefabbbbca")
     assert_is_not_none(mo)
     assert_equal(mo, ["bb", "bbbb"])
예제 #12
0
 def test_basic_groups(self):
     robj = cffi_re2.compile(r'a(b+)')
     mo = robj.search("abbc")
     assert_is_not_none(mo)
     assert_equal(mo.groups(), ("bb",))
예제 #13
0
 def test_flag_ignorecase(self):
     rgx_ci = cffi_re2.compile(r'a(b+)$', flags=cffi_re2.IGNORECASE)
     rgx_cs = cffi_re2.compile(r'a(b+)$')
     # Check case sensitive
     assert_is_none(rgx_cs.match("AB"))
     assert_is_none(rgx_cs.match("Ab"))
     assert_is_none(rgx_cs.match("aB"))
     assert_is_none(rgx_cs.match("aBb"))
     assert_is_none(rgx_cs.match("abB"))
     assert_is_not_none(rgx_cs.match("ab"))
     assert_is_not_none(rgx_cs.match("abb"))
     # Check case insensitive
     assert_is_not_none(rgx_ci.match("AB"))
     assert_is_not_none(rgx_ci.match("Ab"))
     assert_is_not_none(rgx_ci.match("aB"))
     assert_is_not_none(rgx_ci.match("aBb"))
     assert_is_not_none(rgx_ci.match("abB"))
     assert_is_not_none(rgx_ci.match("ab"))
     assert_is_not_none(rgx_ci.match("abb"))
     # Official example
     assert_equal(cffi_re2.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=cffi_re2.IGNORECASE),
                  'Baked Beans & Spam')
예제 #14
0
 def test_basic_search(self):
     robj = cffi_re2.compile(r'b+')
     assert_is_not_none(robj.search('abbcd'))