tests and slightly better profiles
[dbsrgits/SQL-Abstract.git] / t / 11unparse.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use SQL::Abstract::Tree;
6
7 my $sqlat = SQL::Abstract::Tree->new({
8    profile => 'console_monochrome',
9 });
10
11 {
12    my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
13    my $expected_sql =
14       qq{SELECT a, b, c \n} .
15       qq{  FROM foo \n} .
16       qq{  WHERE foo.a = 1 AND foo.b LIKE 'station' };
17    is($sqlat->format($sql), $expected_sql,
18       'simple statement formatted correctly'
19    );
20 }
21
22 {
23    my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
24    my $expected_sql =
25       qq{SELECT * \n} .
26       qq{  FROM (\n} .
27       qq{    SELECT * \n} .
28       qq{      FROM foobar \n} .
29       qq{  ) \n} .
30       qq{  WHERE foo.a = 1 AND foo.b LIKE 'station' };
31
32    is($sqlat->format($sql), $expected_sql,
33       'subquery statement formatted correctly'
34    );
35 }
36
37 {
38    my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
39    my $expected_sql =
40       qq{SELECT * \n} .
41       qq{  FROM lolz \n} .
42       qq{  WHERE (foo.a = 1) AND foo.b LIKE 'station' };
43
44    is($sqlat->format($sql), $expected_sql,
45       'simple statement with parens in where formatted correctly'
46    );
47 }
48
49 done_testing;
50 # stuff we want:
51 #    Nested indentation
52 #    Max Width
53 #    Color coding (console)
54 #    Color coding (html)