def test_sub_function(self): # Python re example def dashrepl(matchobj): if matchobj.group(0) == '-': return ' ' else: return '-' assert_equal(cffi_re2.sub(r'-{1,2}', dashrepl, 'pro-gram--files'), 'pro gram-files') # print() assert_equal(cffi_re2.sub(r'-{1,2}', dashrepl, 'pro----gram-files'), 'pro--gram files')
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')
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'))
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')