import re, random, py from rpython.rlib.rsre import rsre_char, rsre_constants from rpython.rlib.rsre.rpy import get_code, VERSION from rpython.rlib.rsre.test.support import match, fullmatch, Position as P def get_code_and_re(regexp): return get_code(regexp), re.compile(regexp) def test_get_code_repetition(): c1 = get_code(r"a+") c2 = get_code(r"a+") assert c1.pattern == c2.pattern class TestMatch: def test_or(self): r = get_code(r"a|bc|def") assert match(r, "a") assert match(r, "bc") assert match(r, "def") assert not match(r, "ghij") def test_any(self): r = get_code(r"ab.cd") assert match(r, "abXcdef") assert not match(r, "ab\ncdef") assert not match(r, "abXcDef") def test_any_repetition(self): r = get_code(r"ab.*cd") assert match(r, "abXXXXcdef") assert match(r, "abcdef") assert not match(r, "abX\nXcdef") assert not match(r, "abXXXXcDef") def test_any_all(self): r = get_code(r"(?s)ab.cd") assert match(r, "abXcdef") assert match(r, "ab\ncdef") assert not match(r, "ab\ncDef") def test_any_all_repetition(self): r = get_code(r"(?s)ab.*cd") assert match(r, "abXXXXcdef") assert match(r, "abcdef") assert match(r, "abX\nXcdef") assert not match(r, "abX\nXcDef") def test_assert(self): r = get_code(r"abc(?=def)(.)") res = match(r, "abcdefghi") assert res is not None and res.get_mark(1) == P(4) assert not match(r, "abcdeFghi") def test_assert_not(self): r = get_code(r"abc(?!def)(.)") res = match(r, "abcdeFghi") assert res is not None and res.get_mark(1) == P(4) assert not match(r, "abcdefghi") def test_lookbehind(self): r = get_code(r"([a-z]*)(?<=de)") assert match(r, "ade") res = match(r, "adefg") assert res is not None and res.get_mark(1) == P(3) assert not match(r, "abc") assert not match(r, "X") assert not match(r, "eX") def test_negative_lookbehind(self): def found(s): res = match(r, s) assert res is not None return res.get_mark(1) r = get_code(r"([a-z]*)(?