1 from Martel.convert_re import *
2
4 data = (
5 ("a", "a"),
6 ("ab", "ab"),
7 ("a|b", "[ab]"),
8 ("[ab]", "[ab]"),
9 ("a|b|c|d", "[a-d]"),
10 ("ab|bc", "ab|bc"),
11 ("a*", "a*"),
12 ("a+", "a+"),
13 ("a?", "a?"),
14 ("a{3}", "a{3}"),
15 ("a{3,8}", "a{3,8}"),
16 ("a{3,3}", "a{3}"),
17 ("(?:test1)", "(test1)"),
18 ("(?P<foo>test1)", "(?P<foo>test1)"),
19 (".", "."),
20 ("((?P<x>..?)|(?P<y>..*))", "((?P<x>..?)|(?P<y>..*))"),
21 ("\w", "[\\dA-Z_a-z]"),
22 ("\s", "[\\t-\\r ]"),
23 ("\\d", "[\\d]"),
24 ("[0123456789]", "[\\d]"),
25 ("(0|1|2|3|4|5|6|7|8|9)", "([\\d])"),
26 (r"This is (?!not\.)nothing\.", r"This is (?!not\.)nothing\."),
27 (r"This is (?=not\.)nothing\.", r"This is (?=not\.)nothing\."),
28 ("^start", "^start"),
29 ("not^start", "not^start"),
30 ("end$", "end$"),
31 ("end$not", "end$not"),
32 ("[a-z]", "[a-z]"),
33 ("[^a-z]", "[^a-z]"),
34 ("[^b]", "[^b]"),
35 ("[a-zA-Z]", "[A-Za-z]"),
36 ("[ababab]", "[ab]"),
37 ("a{foo,bar}", "a{foo,bar}"),
38 ("a{foo,foo}", "a{foo}"),
39 ("[\\]]", "\\]"),
40 ("[A\\]]", "[A\\]]"),
41 )
42 for input, output in data:
43 result = str(make_expression(input))
44 assert result == output, "input %s : expected %s but got %s" % \
45 (repr(input), repr(output), repr(result))
46
47 if __name__ == "__main__":
48 test()
49