| 1 |
|
| 2 |
|
| 3 |
from rpython.rtyper.test.test_llinterp import gengraph, interpret |
| 4 |
from rpython.rlib.rsre import rsre_core |
| 5 |
from rpython.rlib.rsre.rsre_re import compile |
| 6 |
|
| 7 |
def main(n): |
| 8 |
assert n >= 0 |
| 9 |
pattern = [n] * n |
| 10 |
string = chr(n) * n |
| 11 |
rsre_core.search(pattern, string) |
| 12 |
|
| 13 |
unicodestr = unichr(n) * n |
| 14 |
pattern = rsre_core.CompiledPattern(pattern) |
| 15 |
ctx = rsre_core.UnicodeMatchContext(pattern, unicodestr, |
| 16 |
0, len(unicodestr), 0) |
| 17 |
rsre_core.search_context(ctx) |
| 18 |
|
| 19 |
return 0 |
| 20 |
|
| 21 |
|
| 22 |
def test_gengraph(): |
| 23 |
t, typer, graph = gengraph(main, [int]) |
| 24 |
|
| 25 |
m = compile("(a|b)aaaaa") |
| 26 |
|
| 27 |
def test_match(): |
| 28 |
def f(i): |
| 29 |
if i: |
| 30 |
s = "aaaaaa" |
| 31 |
else: |
| 32 |
s = "caaaaa" |
| 33 |
g = m.match(s) |
| 34 |
if g is None: |
| 35 |
return 3 |
| 36 |
return int("aaaaaa" == g.group(0)) |
| 37 |
assert interpret(f, [3]) == 1 |
| 38 |
assert interpret(f, [0]) == 3 |
| 39 |
|
| 40 |
def test_translates(): |
| 41 |
from rpython.rlib.rsre import rsre_re |
| 42 |
def f(i): |
| 43 |
if i: |
| 44 |
s = "aaaaaa" |
| 45 |
else: |
| 46 |
s = "caaaaa" |
| 47 |
print rsre_re.match("(a|b)aa", s) |
| 48 |
print rsre_re.match("a{4}", s) |
| 49 |
print rsre_re.search("(a|b)aa", s) |
| 50 |
print rsre_re.search("a{4}", s) |
| 51 |
for x in rsre_re.findall("(a|b)a", s): print x |
| 52 |
for x in rsre_re.findall("a{2}", s): print x |
| 53 |
for x in rsre_re.finditer("(a|b)a", s): print x |
| 54 |
for x in rsre_re.finditer("a{2}", s): print x |
| 55 |
for x in rsre_re.split("(a|b)a", s): print x |
| 56 |
for x in rsre_re.split("a{2}", s): print x |
| 57 |
return 0 |
| 58 |
interpret(f, [3]) |