Beispiel #1
0
 def test_group_branch_max_until(self):
     r_code6 = get_code(r'<abc>(ab|c)*a</abc>')
     res = rsre_core.match(r_code6, '<abc>ccabcccaba</abc>def')
     assert (res.get_mark(0), res.get_mark(1)) == (12, 14)
     r_code7 = get_code(r'<abc>((ab)|(c))*a</abc>')
     res = rsre_core.match(r_code7, '<abc>ccabcccaba</abc>def')
     assert (res.get_mark(0), res.get_mark(1)) == (12, 14)
     assert (res.get_mark(2), res.get_mark(3)) == (12, 14)
     assert (res.get_mark(4), res.get_mark(5)) == (11, 12)
Beispiel #2
0
 def test_group_branch_max_until(self):
     r_code6 = get_code(r'<abc>(ab|c)*a</abc>')
     res = rsre_core.match(r_code6, '<abc>ccabcccaba</abc>def')
     assert (res.get_mark(0), res.get_mark(1)) == (12, 14)
     r_code7 = get_code(r'<abc>((ab)|(c))*a</abc>')
     res = rsre_core.match(r_code7, '<abc>ccabcccaba</abc>def')
     assert (res.get_mark(0), res.get_mark(1)) == (12, 14)
     assert (res.get_mark(2), res.get_mark(3)) == (12, 14)
     assert (res.get_mark(4), res.get_mark(5)) == (11, 12)
Beispiel #3
0
 def test_code1(self):
     r_code1 = get_code(r'[abc][def][ghi]')
     res = rsre_core.search(r_code1, "fooahedixxx")
     assert res is None
     res = rsre_core.search(r_code1, "fooahcdixxx")
     assert res is not None
     assert res.span() == (5, 8)
Beispiel #4
0
 def test_code1(self):
     r_code1 = get_code(r'[abc][def][ghi]')
     res = rsre_core.search(r_code1, "fooahedixxx")
     assert res is None
     res = rsre_core.search(r_code1, "fooahcdixxx")
     assert res is not None
     assert res.span() == (5, 8)
Beispiel #5
0
def run_external(t, use_search):
    from pypy.rlib.rsre.test.re_tests import SUCCEED, FAIL, SYNTAX_ERROR
    pattern, s, outcome = t[:3]
    if len(t) == 5:
        repl, expected = t[3:5]
    else:
        assert len(t) == 3
    print 'trying:', t
    try:
        obj = get_code(pattern)
    except re.error:
        if outcome == SYNTAX_ERROR:
            return  # Expected a syntax error
        raise
    if outcome == SYNTAX_ERROR:
        raise Exception("this should have been a syntax error")
    #
    if use_search:
        result = rsre_core.search(obj, s)
    else:
        # Emulate a poor man's search() with repeated match()s
        for i in range(len(s) + 1):
            result = rsre_core.match(obj, s, start=i)
            if result:
                break
    #
    if outcome == FAIL:
        if result is not None:
            raise Exception("succeeded incorrectly")
    elif outcome == SUCCEED:
        if result is None:
            raise Exception("failed incorrectly")
        # Matched, as expected, so now we compute the
        # result string and compare it to our expected result.
        start, end = result.span(0)
        vardict = {
            'found': result.group(0),
            'groups': result.group(),
        }  #'flags': result.re.flags}
        for i in range(1, 100):
            try:
                gi = result.group(i)
                # Special hack because else the string concat fails:
                if gi is None:
                    gi = "None"
            except IndexError:
                gi = "Error"
            vardict['g%d' % i] = gi
        #for i in result.re.groupindex.keys():
        #    try:
        #        gi = result.group(i)
        #        if gi is None:
        #            gi = "None"
        #    except IndexError:
        #        gi = "Error"
        #    vardict[i] = gi
        repl = eval(repl, vardict)
        if repl != expected:
            raise Exception("grouping error: %r should be %r" %
                            (repl, expected))
Beispiel #6
0
def run_external(t, use_search):
    from pypy.rlib.rsre.test.re_tests import SUCCEED, FAIL, SYNTAX_ERROR
    pattern, s, outcome = t[:3]
    if len(t) == 5:
        repl, expected = t[3:5]
    else:
        assert len(t) == 3
    print 'trying:', t
    try:
        obj = get_code(pattern)
    except re.error:
        if outcome == SYNTAX_ERROR:
            return  # Expected a syntax error
        raise
    if outcome == SYNTAX_ERROR:
        raise Exception("this should have been a syntax error")
    #
    if use_search:
        result = rsre_core.search(obj, s)
    else:
        # Emulate a poor man's search() with repeated match()s
        for i in range(len(s)+1):
            result = rsre_core.match(obj, s, start=i)
            if result:
                break
    #
    if outcome == FAIL:
        if result is not None:
            raise Exception("succeeded incorrectly")
    elif outcome == SUCCEED:
        if result is None:
            raise Exception("failed incorrectly")
        # Matched, as expected, so now we compute the
        # result string and compare it to our expected result.
        start, end = result.span(0)
        vardict={'found': result.group(0),
                 'groups': result.group(),
                 }#'flags': result.re.flags}
        for i in range(1, 100):
            try:
                gi = result.group(i)
                # Special hack because else the string concat fails:
                if gi is None:
                    gi = "None"
            except IndexError:
                gi = "Error"
            vardict['g%d' % i] = gi
        #for i in result.re.groupindex.keys():
        #    try:
        #        gi = result.group(i)
        #        if gi is None:
        #            gi = "None"
        #    except IndexError:
        #        gi = "Error"
        #    vardict[i] = gi
        repl = eval(repl, vardict)
        if repl != expected:
            raise Exception("grouping error: %r should be %r" % (repl,
                                                                 expected))
Beispiel #7
0
 def test_group_branch(self):
     r_code5 = get_code(r'<abc>(ab|c)</abc>')
     res = rsre_core.match(r_code5, '<abc>ab</abc>def')
     assert (res.get_mark(0), res.get_mark(1)) == (5, 7)
     res = rsre_core.match(r_code5, '<abc>c</abc>def')
     assert (res.get_mark(0), res.get_mark(1)) == (5, 6)
     res = rsre_core.match(r_code5, '<abc>de</abc>def')
     assert res is None
Beispiel #8
0
 def test_group_branch(self):
     r_code5 = get_code(r'<abc>(ab|c)</abc>')
     res = rsre_core.match(r_code5, '<abc>ab</abc>def')
     assert (res.get_mark(0), res.get_mark(1)) == (5, 7)
     res = rsre_core.match(r_code5, '<abc>c</abc>def')
     assert (res.get_mark(0), res.get_mark(1)) == (5, 6)
     res = rsre_core.match(r_code5, '<abc>de</abc>def')
     assert res is None
Beispiel #9
0
 def test_min_until_0_65535(self):
     r_code2 = get_code(r'<abc>(?:xy)*?xy</abc>')
     res = rsre_core.match(r_code2, '<abc></abc>def')
     assert res is None
     res = rsre_core.match(r_code2, '<abc>xy</abc>def')
     assert res is not None
     res = rsre_core.match(r_code2, '<abc>xyxyxy</abc>def')
     assert res is not None
     res = rsre_core.match(r_code2, '<abc>' + 'xy'*1000 + '</abc>def')
     assert res is not None
Beispiel #10
0
 def test_min_until_0_65535(self):
     r_code2 = get_code(r'<abc>(?:xy)*?xy</abc>')
     res = rsre_core.match(r_code2, '<abc></abc>def')
     assert res is None
     res = rsre_core.match(r_code2, '<abc>xy</abc>def')
     assert res is not None
     res = rsre_core.match(r_code2, '<abc>xyxyxy</abc>def')
     assert res is not None
     res = rsre_core.match(r_code2, '<abc>' + 'xy' * 1000 + '</abc>def')
     assert res is not None
Beispiel #11
0
 def test_max_until_groups(self):
     r_code4 = get_code(r'<abc>(x.)*xy</abc>')
     res = rsre_core.match(r_code4, '<abc>xaxbxy</abc>def')
     assert res is not None
     assert res.get_mark(0) == 7
     assert res.get_mark(1) == 9
Beispiel #12
0
 def test_simple_group(self):
     r_code4 = get_code(r'<abc>(x.)</abc>')
     res = rsre_core.match(r_code4, '<abc>xa</abc>def')
     assert res is not None
     assert res.get_mark(0) == 5
     assert res.get_mark(1) == 7
Beispiel #13
0
 def test_min_repeat_one(self):
     r_code3 = get_code(r'<abc>.{3,5}?y')
     for i in range(8):
         res = rsre_core.match(r_code3, '<abc>' + 'x'*i + 'y')
         assert (res is not None) is (3 <= i <= 5)
Beispiel #14
0
 def test_code3(self):
     r_code1 = get_code(r'<item>\s*<title>(.*?)</title>')
     res = rsre_core.match(r_code1, "<item>  <title>abc</title>def")
     assert res is not None
Beispiel #15
0
 def test_code3(self):
     r_code1 = get_code(r'<item>\s*<title>(.*?)</title>')
     res = rsre_core.match(r_code1, "<item>  <title>abc</title>def")
     assert res is not None
Beispiel #16
0
 def test_pure_literal(self):
     r_code3 = get_code(r'foobar')
     res = rsre_core.search(r_code3, "foo bar foobar baz")
     assert res is not None
     assert res.span() == (8, 14)
Beispiel #17
0
 def test_code2(self):
     r_code2 = get_code(r'<item>\s*<title>(.*?)</title>')
     res = rsre_core.search(r_code2, "foo bar <item>  <title>abc</title>def")
     assert res is not None
     assert res.span() == (8, 34)
Beispiel #18
0
 def test_pure_literal(self):
     r_code3 = get_code(r'foobar')
     res = rsre_core.search(r_code3, "foo bar foobar baz")
     assert res is not None
     assert res.span() == (8, 14)
Beispiel #19
0
 def test_max_until_groups(self):
     r_code4 = get_code(r'<abc>(x.)*xy</abc>')
     res = rsre_core.match(r_code4, '<abc>xaxbxy</abc>def')
     assert res is not None
     assert res.get_mark(0) == 7
     assert res.get_mark(1) == 9
Beispiel #20
0
 def test_simple_group(self):
     r_code4 = get_code(r'<abc>(x.)</abc>')
     res = rsre_core.match(r_code4, '<abc>xa</abc>def')
     assert res is not None
     assert res.get_mark(0) == 5
     assert res.get_mark(1) == 7
Beispiel #21
0
 def test_min_repeat_one(self):
     r_code3 = get_code(r'<abc>.{3,5}?y')
     for i in range(8):
         res = rsre_core.match(r_code3, '<abc>' + 'x' * i + 'y')
         assert (res is not None) is (3 <= i <= 5)
Beispiel #22
0
 def meta_interp_search(self, pattern, string, repeat=1):
     r = get_code(pattern)
     return self.meta_interp(entrypoint2, [list2array(r), llstr(string),
                                           repeat],
                             listcomp=True, backendopt=True)
Beispiel #23
0
 def test_code2(self):
     r_code2 = get_code(r'<item>\s*<title>(.*?)</title>')
     res = rsre_core.search(r_code2,
                            "foo bar <item>  <title>abc</title>def")
     assert res is not None
     assert res.span() == (8, 34)