Example #1
0
    def test_case_sensitivity(self):
        def uni_match(input):
            def func(uni_match):
                return uni_match

            return func(*input)

        def final(input):
            return input

        config.regex_flags = regex.VERBOSE

        lower_regex = "([a-z]+)"
        lower_exp = Expression(lower_regex, [uni_match], [1], final)
        self.assertEquals(lower_exp.findall("aAbcBC"), ["a", "bc"])

        upper_regex = "([A-Z]+)"
        upper_exp = Expression(upper_regex, [uni_match], [1], final)
        self.assertEquals(upper_exp.findall("aAbcBC"), ["A", "BC"])
Example #2
0
    def test_unicode_flag(self):
        def uni_match(input):
            def func(uni_match):
                return uni_match

            return func(*input)

        def final(input):
            return input

        config.regex_flags = config.regex_flags | regex.UNICODE

        imp_regex = "(\w+)"
        implicit_u = Expression(imp_regex, [uni_match], [1], final)
        self.assertEquals(implicit_u.findall("b\xebs"), ["b\xebs"])

        exp_regex = "([\u00c0-\ud7ff]+)"
        explicit_u = Expression(exp_regex, [uni_match], [1], final)
        self.assertEquals(explicit_u.findall("b\u00eb\u2013s"), ["\u00eb\u2013"])
Example #3
0
    def test_expressions(self):
        def greeting(input):
            def func(greeting):
                return greeting
            return func(*input)

        def final(input):
            for i in input:
                if i is not None:
                    return i

        regex = "(hi)|(hi)"

        exp = Expression(regex, [greeting, greeting], [1, 1], final)

        self.assertIsInstance(exp, Expression)
        self.assertEquals(exp.findall("hi"), ["hi"])
Example #4
0
    def test_expressions(self):
        def greeting(input):
            def func(greeting):
                return greeting

            return func(*input)

        def final(input):
            for i in input:
                if i is not None:
                    return i

        regex = "(hi)|(hi)"

        exp = Expression(regex, [greeting, greeting], [1, 1], final)

        self.assertIsInstance(exp, Expression)
        self.assertEquals(exp.findall("hi"), ["hi"])