X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F10test.t;h=2e1e55968d41aee396cc8defc9c3e1533f04dc92;hb=cf5b7ab163f8ac123ebc9bb1156e79646cd5bd2f;hp=213274067fa97c6592e7a1461a1ccd531292442c;hpb=10e6c94609fc94467ef8f281ffe192d8038ffc9e;p=scpubgit%2FQ-Branch.git diff --git a/t/10test.t b/t/10test.t index 2132740..2e1e559 100644 --- a/t/10test.t +++ b/t/10test.t @@ -1,14 +1,11 @@ -#!/usr/bin/perl - use strict; use warnings; -use List::Util qw(sum); use Test::More; -use Data::Dumper; -$Data::Dumper::Terse = 1; -$Data::Dumper::Sortkeys = 1; +use SQL::Abstract::Test import => [qw( + eq_sql_bind eq_sql eq_bind is_same_sql_bind dumper $sql_differ +)]; my @sql_tests = ( # WHERE condition - equal @@ -260,10 +257,10 @@ my @sql_tests = ( }, { equal => 0, - opts => { parenthesis_significant => 1 }, statements => [ - q/SELECT foo FROM bar WHERE a IN (1,2,3)/, q/SELECT foo FROM bar WHERE a IN (1,3,2)/, + q/SELECT foo FROM bar WHERE a IN 1,2,3/, + q/SELECT foo FROM bar WHERE a IN (1,2,3)/, q/SELECT foo FROM bar WHERE a IN ((1,2,3))/, ] }, @@ -618,6 +615,13 @@ my @sql_tests = ( ], }, { + equal => 1, + statements => [ + q/ORDER BY name + ?, [me].[id]/, + q/ORDER BY name + ? ASC, [me].[id]/, + ], + }, + { equal => 0, opts => { order_by_asc_significant => 1 }, statements => [ @@ -766,6 +770,14 @@ my @sql_tests = ( ) AND [source] = ? ) )', ], }, + { + equal => 1, + statements => [ + 'WHERE foo = ? FETCH FIRST 1 ROWS ONLY', + 'WHERE ( foo = ? ) FETCH FIRST 1 ROWS ONLY', + 'WHERE (( foo = ? )) FETCH FIRST 1 ROWS ONLY', + ], + }, ); my @bind_tests = ( @@ -960,10 +972,6 @@ my @bind_tests = ( }, ); -use_ok('SQL::Abstract::Test', import => [qw( - eq_sql_bind eq_sql eq_bind is_same_sql_bind -)]); - for my $test (@sql_tests) { # this does not work on 5.8.8 and earlier :( @@ -995,11 +1003,11 @@ for my $test (@sql_tests) { if ($equal ^ $test->{equal}) { my ($ast1, $ast2) = map { SQL::Abstract::Test::parse ($_) } ($sql1, $sql2); - $_ = Dumper $_ for ($ast1, $ast2); + $_ = dumper($_) for ($ast1, $ast2); diag "sql1: $sql1"; diag "sql2: $sql2"; - note $SQL::Abstract::Test::sql_differ; + note $sql_differ || 'No differences found'; note "ast1: $ast1"; note "ast2: $ast2"; } @@ -1024,8 +1032,8 @@ for my $test (@bind_tests) { } if ($equal ^ $test->{equal}) { - diag("bind1: " . Dumper($bind1)); - diag("bind2: " . Dumper($bind2)); + diag("bind1: " . dumper($bind1)); + diag("bind2: " . dumper($bind2)); } } } @@ -1059,7 +1067,7 @@ ok (! eq_sql ( 'SELECT owner_name FROM books me WHERE ( sUOrce = ? )', )); like( - $SQL::Abstract::Test::sql_differ, + $sql_differ, qr/\Q[ source ] != [ sUOrce ]/, 'expected debug of literal diff', ); @@ -1069,7 +1077,7 @@ ok (! eq_sql ( 'SELECT owner_name FROM books me GROUP BY owner_name', )); like( - $SQL::Abstract::Test::sql_differ, + $sql_differ, qr/\QOP [ORDER BY] != [GROUP BY]/, 'expected debug of op diff', ); @@ -1080,9 +1088,22 @@ ok (! eq_sql ( )); like( - $SQL::Abstract::Test::sql_differ, + $sql_differ, qr|\Q[WHERE source = ?] != [N/A]|, 'expected debug of missing branch', ); + +ok (eq_sql_bind ( + \[ 'SELECT foo FROM bar WHERE baz = ? or buzz = ?', [ {} => 1 ], 2 ], + 'SELECT foo FROM bar WHERE (baz = ?) OR buzz = ?', + [ [ {} => 1 ], 2 ], +), 'arrayrefref unpacks correctly' ); + +is_same_sql_bind( + \[ 'SELECT foo FROM bar WHERE baz = ? or buzz = ?', [ {} => 1 ], 2 ], + \[ 'SELECT foo FROM bar WHERE (( baz = ? OR (buzz = ?) ))', [ {} => 1 ], 2 ], + 'double arrayrefref unpacks correctly' +); + done_testing;