5 use SQL::Abstract::Tree;
7 subtest no_formatting => sub {
8 my $sqlat = SQL::Abstract::Tree->new;
11 my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
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'
20 my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
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'
29 my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
31 "SELECT * FROM lolz WHERE (foo.a = 1) AND foo.b LIKE 'station' ";
33 is($sqlat->format($sql), $expected_sql,
34 'simple statement with parens in where formatted correctly'
40 subtest console_monochrome => sub {
41 my $sqlat = SQL::Abstract::Tree->new({
42 profile => 'console_monochrome',
46 my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
48 qq{SELECT a, b, c \n} .
50 qq{ WHERE foo.a = 1 AND foo.b LIKE 'station' };
51 is($sqlat->format($sql), $expected_sql,
52 'simple statement formatted correctly'
57 my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
64 qq{ WHERE foo.a = 1 AND foo.b LIKE 'station' };
66 is($sqlat->format($sql), $expected_sql,
67 'subquery statement formatted correctly'
72 my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
76 qq{ WHERE (foo.a = 1) AND foo.b LIKE 'station' };
78 is($sqlat->format($sql), $expected_sql,
79 'simple statement with parens in where formatted correctly'
86 my $sqlat = SQL::Abstract::Tree->new({
91 my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
93 qq{<span class="select">SELECT</span> a, b, c <br />\n} .
94 qq{ <span class="from">FROM</span> foo <br />\n} .
95 qq{ <span class="where">WHERE</span> foo.a = 1 AND foo.b LIKE 'station' };
96 is($sqlat->format($sql), $expected_sql,
97 'simple statement formatted correctly'
102 my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
104 qq{<span class="select">SELECT</span> * <br />\n} .
105 qq{ <span class="from">FROM</span> (<br />\n} .
106 qq{ <span class="select">SELECT</span> * <br />\n} .
107 qq{ <span class="from">FROM</span> foobar <br />\n} .
108 qq{ ) <br />\n} .
109 qq{ <span class="where">WHERE</span> foo.a = 1 AND foo.b LIKE 'station' };
111 is($sqlat->format($sql), $expected_sql,
112 'subquery statement formatted correctly'
117 my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
119 qq{<span class="select">SELECT</span> * <br />\n} .
120 qq{ <span class="from">FROM</span> lolz <br />\n} .
121 qq{ <span class="where">WHERE</span> (foo.a = 1) AND foo.b LIKE 'station' };
123 is($sqlat->format($sql), $expected_sql,
124 'simple statement with parens in where formatted correctly'
130 subtest configuration => sub {
131 my $sqlat = SQL::Abstract::Tree->new({
132 profile => 'console_monochrome',
133 indent_string => "\t",
139 my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
141 qq{SELECT a, b, c \r\n} .
142 qq{\tFROM foo \r\n} .
143 qq{\tWHERE foo.a = 1 AND foo.b LIKE 'station' };
144 is($sqlat->format($sql), $expected_sql,
145 'simple statement formatted correctly'
150 my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
154 qq{\t\tSELECT * \r\n} .
155 qq{\t\t\tFROM foobar \r\n} .
157 qq{\tWHERE foo.a = 1 AND foo.b LIKE 'station' };
159 is($sqlat->format($sql), $expected_sql,
160 'subquery statement formatted correctly'
165 my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
168 qq{\tFROM lolz \r\n} .
169 qq{\tWHERE (foo.a = 1) AND foo.b LIKE 'station' };
171 is($sqlat->format($sql), $expected_sql,
172 'simple statement with parens in where formatted correctly'
181 # Color coding (html)