From: Arthur Axel "fREW" Schmidt Date: Sat, 4 Sep 2010 01:22:34 +0000 (+0000) Subject: test for no formatting X-Git-Tag: v1.70~91^2~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=54750c7a150274c9711c8797b3c14a59f496a224;hp=3be357b0bb2c31c729e14e3244428372810a4263;p=dbsrgits%2FSQL-Abstract.git test for no formatting --- diff --git a/Makefile.PL b/Makefile.PL index b126ac0..3c71b5d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -13,7 +13,7 @@ all_from 'lib/SQL/Abstract.pm'; requires 'List::Util' => 0; requires 'Scalar::Util' => 0; -test_requires "Test::More" => 0; +test_requires "Test::More" => 0.96; test_requires "Test::Exception" => 0; test_requires "Test::Warn" => 0; test_requires "Storable" => 0; # for cloning in tests diff --git a/t/11unparse.t b/t/11unparse.t index e9f9623..edad5ee 100644 --- a/t/11unparse.t +++ b/t/11unparse.t @@ -4,47 +4,83 @@ 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; +}; done_testing; # stuff we want: