def test_construct_regexp(self):
        res = [
            (u"\\.", None),
            (u"..", None),
            (u"\\.", None),
            (u"^a\aa[ha-z]k{1,3}h*h+h?(x|yy)(a+b|cd)$", None),
            (u"(?=Asimov)", None),
            (u"(?!Asimov)", None),
            (u"(?<=abc)def", None),
            (u"(?<!foo)", None),
            (u"(?:foo)", None),
            (u"(?#foo)", u""),
            (u"(.+) \1", None),
            (u"\\A\\b\\B\\d\\D\\s\\S\\w\\W\\Z\a",
             u"\\A\\b\\B[\\d][\\D][\\s][\\S][\\w][\\W]\\Z\a"),
            (u"a{3,5}?a+?a*?a??", None),
            (u"^foo$", None),
            (u"[-+]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?",
             u"[\\-\\+]?([\\d]+(\\.[\\d]*)?|\\.[\\d]+)([eE][\\-\\+]?[\\d]+)?"),
            (u"(\$\d*)", u"(\\$[\\d]*)"),
            (u"\\$\\.\\^\\[\\]\\:\\-\\+\\?\\\\", None),
            (u"[^a][^ab]", None),
            (u"[ab][abc]", None),
            (u"[.]", u"\\."),
            (u"[^a-z]", None),
            (u"[^a-z\w]", None),
        ]

        for r, o in res:
            if o is None:
                o = r
            self.assertEqual(re_replace_literals(r, {}), o)
    def test_construct_regexp(self):
        res = [
            (u"\\.", None),
            (u"..", None),
            (u"\\.", None),
            (u"^a\aa[ha-z]k{1,3}h*h+h?(x|yy)(a+b|cd)$", None),
            (u"(?=Asimov)", None),
            (u"(?!Asimov)", None),
            (u"(?<=abc)def", None),
            (u"(?<!foo)", None),
            (u"(?#foo)", u""),
            (u"(.+) \1", None),
            (u"\\A\\b\\B\\d\\D\\s\\S\\w\\W\\Z\a",
             u"\\A\\b\\B[\\d][\\D][\\s][\\S][\\w][\\W]\\Z\a"),
            (u"a{3,5}?a+?a*?a??", None),
            (u"^foo$", None),
            (u"[-+]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?",
             u"[\\-\\+]?([\\d]+(\\.[\\d]*)?|\\.[\\d]+)([eE][\\-\\+]?[\\d]+)?"),
            (u"(\\$\\d*)", u"(\\$[\\d]*)"),
            (u"\\$\\.\\^\\[\\]\\:\\-\\+\\?\\\\", None),
            (u"[^a][^ab]", None),
            (u"[ab][abc]", None),
            (u"[.]", u"\\."),
            (u"[^a-z]", None),
            (u"[^a-z\\w]", None),
            ("(x|yy)", None),
        ]

        for r, o in res:
            if o is None:
                o = r
            self.assertEqual(re_replace_literals(r, {}), o)
Exemple #3
0
    def test_construct_regexp_37_change(self):
        # Starting with 3.7 the parser throws out some subpattern
        # nodes. We try to recover them or test against the old and new result.
        res = [
            (u"(?:foo)", ("(?:foo)", "foo")),
            (u"(?:foo)x", ("(?:foo)x", "foox")),
            (u"(?:foo)(?:bar)", ("(?:foo)(?:bar)", "foobar")),
            (u"(?:foo|bla)", None),
            (u"(?:foo|bla)x", None),
        ]

        for r, o in res:
            out = re_replace_literals(r, {})
            if o is None:
                o = r
            if isinstance(o, tuple):
                assert out in o
            else:
                assert out == o
    def test_construct_regexp_37_change(self):
        # Starting with 3.7 the parser throws out some subpattern
        # nodes. We try to recover them or test against the old and new result.
        res = [
            (u"(?:foo)", ("(?:foo)", "foo")),
            (u"(?:foo)x", ("(?:foo)x", "foox")),
            (u"(?:foo)(?:bar)", ("(?:foo)(?:bar)", "foobar")),
            (u"(?:foo|bla)", None),
            (u"(?:foo|bla)x", None),
        ]

        for r, o in res:
            out = re_replace_literals(r, {})
            if o is None:
                o = r
            if isinstance(o, tuple):
                assert out in o
            else:
                assert out == o