Commit | Line | Data |
d49e5323 |
1 | use strict; |
2 | use warnings; |
3 | |
3be357b0 |
4 | use Test::More; |
d49e5323 |
5 | use SQL::Abstract::Tree; |
6 | |
54750c7a |
7 | subtest no_formatting => sub { |
8 | my $sqlat = SQL::Abstract::Tree->new; |
9 | |
10 | { |
11 | my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'"; |
12 | my $expected_sql = |
13 | "SELECT a, b, c FROM foo WHERE foo.a = 1 AND foo.b LIKE 'station' "; |
14 | is($sqlat->format($sql), $expected_sql, |
15 | 'simple statement formatted correctly' |
16 | ); |
17 | } |
18 | |
19 | { |
20 | my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'"; |
21 | my $expected_sql = |
22 | "SELECT * FROM (SELECT * FROM foobar ) WHERE foo.a = 1 AND foo.b LIKE 'station' "; |
23 | is($sqlat->format($sql), $expected_sql, |
24 | 'subquery statement formatted correctly' |
25 | ); |
26 | } |
27 | |
28 | { |
29 | my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'"; |
30 | my $expected_sql = |
31 | "SELECT * FROM lolz WHERE (foo.a = 1) AND foo.b LIKE 'station' "; |
32 | |
33 | is($sqlat->format($sql), $expected_sql, |
34 | 'simple statement with parens in where formatted correctly' |
35 | ); |
36 | } |
37 | done_testing; |
38 | }; |
39 | |
40 | subtest console_monochrome => sub { |
41 | my $sqlat = SQL::Abstract::Tree->new({ |
42 | profile => 'console_monochrome', |
43 | }); |
44 | |
45 | { |
46 | my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'"; |
47 | my $expected_sql = |
48 | qq{SELECT a, b, c \n} . |
49 | qq{ FROM foo \n} . |
50 | qq{ WHERE foo.a = 1 AND foo.b LIKE 'station' }; |
51 | is($sqlat->format($sql), $expected_sql, |
52 | 'simple statement formatted correctly' |
53 | ); |
54 | } |
55 | |
56 | { |
57 | my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'"; |
58 | my $expected_sql = |
59 | qq{SELECT * \n} . |
60 | qq{ FROM (\n} . |
61 | qq{ SELECT * \n} . |
62 | qq{ FROM foobar \n} . |
63 | qq{ ) \n} . |
64 | qq{ WHERE foo.a = 1 AND foo.b LIKE 'station' }; |
65 | |
66 | is($sqlat->format($sql), $expected_sql, |
67 | 'subquery statement formatted correctly' |
68 | ); |
69 | } |
70 | |
71 | { |
72 | my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'"; |
73 | my $expected_sql = |
74 | qq{SELECT * \n} . |
75 | qq{ FROM lolz \n} . |
76 | qq{ WHERE (foo.a = 1) AND foo.b LIKE 'station' }; |
77 | |
78 | is($sqlat->format($sql), $expected_sql, |
79 | 'simple statement with parens in where formatted correctly' |
80 | ); |
81 | } |
82 | done_testing; |
83 | }; |
a24cc3a0 |
84 | |
3be357b0 |
85 | done_testing; |
d49e5323 |
86 | # stuff we want: |
87 | # Nested indentation |
88 | # Max Width |
89 | # Color coding (console) |
90 | # Color coding (html) |