paulb@2 | 1 | #!/usr/bin/env python |
paulb@2 | 2 | |
paulb@2 | 3 | "Test sqlliterals." |
paulb@2 | 4 | |
paulb@2 | 5 | import sqlliterals.pyparser |
paulb@2 | 6 | import sqlliterals.regexp |
paulb@2 | 7 | |
paulb@2 | 8 | def show(regions): |
paulb@2 | 9 | non_literal = 1 |
paulb@2 | 10 | for region in regions: |
paulb@2 | 11 | print region, |
paulb@2 | 12 | if non_literal: |
paulb@2 | 13 | print "(NL)", |
paulb@2 | 14 | else: |
paulb@2 | 15 | print "(L)", |
paulb@2 | 16 | non_literal = not non_literal |
paulb@2 | 17 | print |
paulb@2 | 18 | |
paulb@2 | 19 | l = [ |
paulb@2 | 20 | "a = a", |
paulb@2 | 21 | "a = 'a'", |
paulb@2 | 22 | "'a' = a", |
paulb@2 | 23 | "'a' = 'a'", |
paulb@2 | 24 | "a = ''''", |
paulb@2 | 25 | "'''' = a", |
paulb@2 | 26 | "'''' = ''''", |
paulb@2 | 27 | "a = '''a'''", |
paulb@2 | 28 | "'''a''' = a", |
paulb@2 | 29 | "'''a''' = '''a'''" |
paulb@2 | 30 | ] |
paulb@2 | 31 | |
paulb@2 | 32 | for s in l: |
paulb@2 | 33 | show(sqlliterals.pyparser.parseString(s)) |
paulb@2 | 34 | show(sqlliterals.regexp.parseString(s)) |
paulb@2 | 35 | |
paulb@4 | 36 | l2 = [ |
paulb@5 | 37 | ("a = ?", "a = %s"), |
paulb@5 | 38 | ("a = '?'", "a = '?'"), |
paulb@5 | 39 | ("'a' = ?", "'a' = %s"), |
paulb@5 | 40 | ("'a' = '?'", "'a' = '?'"), |
paulb@5 | 41 | ("a = ''?''", "a = ''%s''"), |
paulb@5 | 42 | ("'''' = ?", "'''' = %s"), |
paulb@5 | 43 | ("'''' = ''?''", "'''' = ''%s''"), |
paulb@5 | 44 | ("a = '''?'''", "a = '''?'''"), |
paulb@5 | 45 | ("'''a''' = ?", "'''a''' = %s"), |
paulb@5 | 46 | ("'''a''' = '''?'''", "'''a''' = '''?'''") |
paulb@4 | 47 | ] |
paulb@4 | 48 | |
paulb@5 | 49 | for s, exp in l2: |
paulb@5 | 50 | s2 = sqlliterals.pyparser.replace("?", "%s", s) |
paulb@5 | 51 | print s, s2, s2 == exp |
paulb@5 | 52 | s2 = sqlliterals.regexp.replace("?", "%s", s) |
paulb@5 | 53 | print s, s2, s2 == exp |
paulb@4 | 54 | |
paulb@2 | 55 | # vim: tabstop=4 expandtab shiftwidth=4 |