X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F11unparse.t;h=a91b88d68e3b1bd38b5293b635e948c5fffbe7d6;hb=7e5600e994c4f4f7958a19cc246d43bdee9d3890;hp=e9f9623615e22da4b28e63f9ddab6be6a7821a9d;hpb=3be357b0bb2c31c729e14e3244428372810a4263;p=dbsrgits%2FSQL-Abstract.git
diff --git a/t/11unparse.t b/t/11unparse.t
index e9f9623..a91b88d 100644
--- a/t/11unparse.t
+++ b/t/11unparse.t
@@ -4,51 +4,178 @@ use warnings;
use Test::More;
use SQL::Abstract::Tree;
-my $sqlat = SQL::Abstract::Tree->new({
- profile => 'console_monochrome',
-});
-
-{
- my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
- my $expected_sql =
- qq{SELECT a, b, c \n} .
- qq{ FROM foo \n} .
- qq{ WHERE foo.a = 1 AND foo.b LIKE 'station' };
- is($sqlat->format($sql), $expected_sql,
- 'simple statement formatted correctly'
- );
-}
-
-{
- my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
- my $expected_sql =
- qq{SELECT * \n} .
- qq{ FROM (\n} .
- qq{ SELECT * \n} .
- qq{ FROM foobar \n} .
- qq{ ) \n} .
- qq{ WHERE foo.a = 1 AND foo.b LIKE 'station' };
-
- is($sqlat->format($sql), $expected_sql,
- 'subquery statement formatted correctly'
- );
-}
-
-{
- my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
- my $expected_sql =
- qq{SELECT * \n} .
- qq{ FROM lolz \n} .
- qq{ WHERE (foo.a = 1) AND foo.b LIKE 'station' };
-
- is($sqlat->format($sql), $expected_sql,
- 'simple statement with parens in where formatted correctly'
- );
-}
+subtest no_formatting => sub {
+ my $sqlat = SQL::Abstract::Tree->new;
+
+ {
+ my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
+ my $expected_sql =
+ "SELECT a, b, c FROM foo WHERE foo.a = 1 AND foo.b LIKE 'station' ";
+ is($sqlat->format($sql), $expected_sql,
+ 'simple statement formatted correctly'
+ );
+ }
+
+ {
+ my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
+ my $expected_sql =
+ "SELECT * FROM (SELECT * FROM foobar ) WHERE foo.a = 1 AND foo.b LIKE 'station' ";
+ is($sqlat->format($sql), $expected_sql,
+ 'subquery statement formatted correctly'
+ );
+ }
+
+ {
+ my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
+ my $expected_sql =
+ "SELECT * FROM lolz WHERE (foo.a = 1) AND foo.b LIKE 'station' ";
+
+ is($sqlat->format($sql), $expected_sql,
+ 'simple statement with parens in where formatted correctly'
+ );
+ }
+ done_testing;
+};
+
+subtest console_monochrome => sub {
+ my $sqlat = SQL::Abstract::Tree->new({
+ profile => 'console_monochrome',
+ });
+
+ {
+ my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
+ my $expected_sql =
+ qq{SELECT a, b, c \n} .
+ qq{ FROM foo \n} .
+ qq{ WHERE foo.a = 1 AND foo.b LIKE 'station' };
+ is($sqlat->format($sql), $expected_sql,
+ 'simple statement formatted correctly'
+ );
+ }
+
+ {
+ my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
+ my $expected_sql =
+ qq{SELECT * \n} .
+ qq{ FROM (\n} .
+ qq{ SELECT * \n} .
+ qq{ FROM foobar \n} .
+ qq{ ) \n} .
+ qq{ WHERE foo.a = 1 AND foo.b LIKE 'station' };
+
+ is($sqlat->format($sql), $expected_sql,
+ 'subquery statement formatted correctly'
+ );
+ }
+
+ {
+ my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
+ my $expected_sql =
+ qq{SELECT * \n} .
+ qq{ FROM lolz \n} .
+ qq{ WHERE (foo.a = 1) AND foo.b LIKE 'station' };
+
+ is($sqlat->format($sql), $expected_sql,
+ 'simple statement with parens in where formatted correctly'
+ );
+ }
+ done_testing;
+};
+
+subtest html => sub {
+ my $sqlat = SQL::Abstract::Tree->new({
+ profile => 'html',
+ });
+
+ {
+ my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
+ my $expected_sql =
+ qq{SELECT a, b, c
\n} .
+ qq{ FROM foo
\n} .
+ qq{ WHERE foo.a = 1 AND foo.b LIKE 'station' };
+ is($sqlat->format($sql), $expected_sql,
+ 'simple statement formatted correctly'
+ );
+ }
+
+ {
+ my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
+ my $expected_sql =
+ qq{SELECT *
\n} .
+ qq{ FROM (
\n} .
+ qq{ SELECT *
\n} .
+ qq{ FROM foobar
\n} .
+ qq{ )
\n} .
+ qq{ WHERE foo.a = 1 AND foo.b LIKE 'station' };
+
+ is($sqlat->format($sql), $expected_sql,
+ 'subquery statement formatted correctly'
+ );
+ }
+
+ {
+ my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
+ my $expected_sql =
+ qq{SELECT *
\n} .
+ qq{ FROM lolz
\n} .
+ qq{ WHERE (foo.a = 1) AND foo.b LIKE 'station' };
+
+ is($sqlat->format($sql), $expected_sql,
+ 'simple statement with parens in where formatted correctly'
+ );
+ }
+ done_testing;
+};
+
+subtest configuration => sub {
+ my $sqlat = SQL::Abstract::Tree->new({
+ profile => 'console_monochrome',
+ indent_string => "\t",
+ indent_amount => 1,
+ newline => "\r\n",
+ });
+
+ {
+ my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
+ my $expected_sql =
+ qq{SELECT a, b, c \r\n} .
+ qq{\tFROM foo \r\n} .
+ qq{\tWHERE foo.a = 1 AND foo.b LIKE 'station' };
+ is($sqlat->format($sql), $expected_sql,
+ 'simple statement formatted correctly'
+ );
+ }
+
+ {
+ my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
+ my $expected_sql =
+ qq{SELECT * \r\n} .
+ qq{\tFROM (\r\n} .
+ qq{\t\tSELECT * \r\n} .
+ qq{\t\t\tFROM foobar \r\n} .
+ qq{\t) \r\n} .
+ qq{\tWHERE foo.a = 1 AND foo.b LIKE 'station' };
+
+ is($sqlat->format($sql), $expected_sql,
+ 'subquery statement formatted correctly'
+ );
+ }
+
+ {
+ my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
+ my $expected_sql =
+ qq{SELECT * \r\n} .
+ qq{\tFROM lolz \r\n} .
+ qq{\tWHERE (foo.a = 1) AND foo.b LIKE 'station' };
+
+ is($sqlat->format($sql), $expected_sql,
+ 'simple statement with parens in where formatted correctly'
+ );
+ }
+ done_testing;
+};
done_testing;
# stuff we want:
-# Nested indentation
# Max Width
-# Color coding (console)
# Color coding (html)