예제 #1
0
 def test_re_compatibility(self):
     """Test compatibility with the Python re library"""
     #
     cm = cffi_re2.search(r'a(b+)', "abbc")
     rm = pyre.search(r'a(b+)', "abbc")
     assert_equal(cm.groups(), rm.groups())
     #
     cm = cffi_re2.match(r'b+', 'abbcd')
     rm = pyre.match(r'b+', 'abbcd')
     assert_equal(cm, rm)
     # Match without groups
     cm = cffi_re2.match(r'[abc]+', 'abbcd')
     rm = pyre.match(r'[abc]+', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     # Full match regex should match
     cm = cffi_re2.match(r'([abc]+)', 'abbcd')
     rm = pyre.match(r'([abc]+)', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     assert_equal(cm.group(0), rm.group(0))
     assert_equal(cm.group(1), rm.group(1))
     cm = cffi_re2.match(r'([ab]+)(c+)', 'abbcd')
     rm = pyre.match(r'([ab]+)(c+)', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     assert_equal(cm.group(0), rm.group(0))
     assert_equal(cm.group(1), rm.group(1))
     assert_equal(cm.group(2), rm.group(2))
예제 #2
0
 def test_re_compatibility(self):
     """Test compatibility with the Python re library"""
     #
     cm = cffi_re2.search(r'a(b+)', "abbc")
     rm = pyre.search(r'a(b+)', "abbc")
     assert_equal(cm.groups(), rm.groups())
     #
     cm = cffi_re2.match(r'b+', 'abbcd')
     rm = pyre.match(r'b+', 'abbcd')
     assert_equal(cm, rm)
     # Match without groups
     cm = cffi_re2.match(r'[abc]+', 'abbcd')
     rm = pyre.match(r'[abc]+', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     # Full match regex should match
     cm = cffi_re2.match(r'([abc]+)', 'abbcd')
     rm = pyre.match(r'([abc]+)', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     assert_equal(cm.group(0), rm.group(0))
     assert_equal(cm.group(1), rm.group(1))
     cm = cffi_re2.match(r'([ab]+)(c+)', 'abbcd')
     rm = pyre.match(r'([ab]+)(c+)', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     assert_equal(cm.group(0), rm.group(0))
     assert_equal(cm.group(1), rm.group(1))
     assert_equal(cm.group(2), rm.group(2))
예제 #3
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'))
예제 #4
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'))
예제 #5
0
 def test_optional_groups(self):
     result = cffi_re2.search(r"(foo)?bar", "bar")
     print(result.ranges)
     assert_equal(result.group(0), "bar")
     assert_is_none(result.group(1))
     assert_equal(result.groups(), (None, ))
예제 #6
0
 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"),
                  [])
예제 #7
0
 def test_optional_groups(self):
     result = cffi_re2.search(r"(foo)?bar", "bar")
     print(result.ranges)
     assert_equal(result.group(0), "bar")
     assert_is_none(result.group(1))
     assert_equal(result.groups(), (None,))
예제 #8
0
 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"), [])