def test_findall_overlapping(self): """Check overlapping matches with findall""" # Prerequisited assert_equal(cffi_re2.findall(r'-{1,2}', 'program-files'), ['-']) assert_equal(cffi_re2.findall(r'-{1,2}', 'pro--gram-files'), ['--', '-']) assert_equal(cffi_re2.findall(r'-{1,2}', 'pro---gram-files'), ['--', '-', '-']) # Actual test assert_equal(cffi_re2.findall(r'-{1,2}', 'pro----gram-files'), ['--', '--', '-'])
def test_findall_subgroups(self): mo = cffi_re2.findall(r'ab+', "abbcdefabbbbca") assert_equal(mo, ["abb", "abbbb"]) mo = cffi_re2.findall(r'a(b+)', "abbcdefabbbbca") assert_equal(mo, ["bb", "bbbb"]) mo = cffi_re2.findall(r'(a)(b+)', "abbcdefabbbbca") assert_equal(mo, [("a", "bb"), ("a", "bbbb")]) mo = cffi_re2.findall(r'(a)(b)(b+)', "abbcdefabbbbca") assert_equal(mo, [("a", "b", "b"), ("a", "b", "bbb")])
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_optional_groups(self): assert_equal(cffi_re2.findall(r"(foo)?bar", "bar"), [''])
def test_more_x(self): assert_is_none(cffi_re2.search(r"<(a|span|div|table)", "Kapazitäten")) assert_equal(cffi_re2.findall(r"<(a|span|div|table)", "Kapazitäten"), [])