X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F00new.t;h=b6927da2fa8175825627af98ee2852f2127e8776;hb=6f2a5b668d6d34e8aee21c2b0cf51fdbf5dee991;hp=1952f94d840dbef4f46b5c8c3abfc0abc8f054fa;hpb=32eab2da957ea33622610a8abc271c7855147904;p=dbsrgits%2FSQL-Abstract.git diff --git a/t/00new.t b/t/00new.t old mode 100755 new mode 100644 index 1952f94..b6927da --- a/t/00new.t +++ b/t/00new.t @@ -1,20 +1,25 @@ -#!/usr/bin/perl -I. -w +#!/usr/bin/perl use strict; -use vars qw($TESTING); -$TESTING = 1; -use Test; +use warnings; +use Test::More; -# use a BEGIN block so we print our plan before SQL::Abstract is loaded -BEGIN { plan tests => 14 } +use SQL::Abstract::Test import => ['is_same_sql_bind']; -use SQL::Abstract; +#LDNOTE: renamed all "bind" into "where" because that's what they are my @handle_tests = ( #1 { args => {logic => 'OR'}, - stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )' +# stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )' +# LDNOTE: modified the line above (changing the test suite!!!) because +# the test was not consistent with the doc: hashrefs should not be +# influenced by the current logic, they always mean 'AND'. So +# { a => 4, b => 0} should ALWAYS mean ( a = ? AND b = ? ). +# +# acked by RIBASUSHI + stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' }, #2 { @@ -34,7 +39,10 @@ my @handle_tests = ( #5 { args => {cmp => "=", logic => 'or'}, - stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )' +# LDNOTE idem +# stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )' +# acked by RIBASUSHI + stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' }, #6 { @@ -44,7 +52,10 @@ my @handle_tests = ( #7 { args => {logic => "or", cmp => "like"}, - stmt => 'SELECT * FROM test WHERE ( a LIKE ? OR b LIKE ? )' +# LDNOTE idem +# stmt => 'SELECT * FROM test WHERE ( a LIKE ? OR b LIKE ? )' +# acked by RIBASUSHI + stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )' }, #8 { @@ -75,29 +86,37 @@ my @handle_tests = ( { args => {convert => "lower"}, stmt => 'SELECT * FROM test WHERE ( ( LOWER(ticket) = LOWER(?) ) OR ( LOWER(hostname) = LOWER(?) ) OR ( LOWER(taco) = LOWER(?) ) OR ( LOWER(salami) = LOWER(?) ) )', - bind => [ { ticket => 11 }, { hostname => 11 }, { taco => 'salad' }, { salami => 'punch' } ], + where => [ { ticket => 11 }, { hostname => 11 }, { taco => 'salad' }, { salami => 'punch' } ], }, #14 { args => {convert => "upper"}, stmt => 'SELECT * FROM test WHERE ( ( UPPER(hostname) IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) AND ( ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) ) ) OR ( UPPER(tack) BETWEEN UPPER(?) AND UPPER(?) ) OR ( ( ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) ) AND ( ( UPPER(e) != UPPER(?) ) OR ( UPPER(e) != UPPER(?) ) ) AND UPPER(q) NOT IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) ) )', - bind => [ { ticket => [11, 12, 13], hostname => { in => ['ntf', 'avd', 'bvd', '123'] } }, + where => [ { ticket => [11, 12, 13], + hostname => { in => ['ntf', 'avd', 'bvd', '123'] } }, { tack => { between => [qw/tick tock/] } }, - { a => [qw/b c d/], e => { '!=', [qw(f g)] }, q => { 'not in', [14..20] } } ], + { a => [qw/b c d/], + e => { '!=', [qw(f g)] }, + q => { 'not in', [14..20] } } ], }, ); + +plan tests => (1 + scalar(@handle_tests)); + +use_ok('SQL::Abstract'); + for (@handle_tests) { - local $" = ', '; - #print "creating a handle with args ($_->{args}): "; - my $sql = SQL::Abstract->new($_->{args}); - my $bind = $_->{bind} || { a => 4, b => 0}; - my($stmt, @bind) = $sql->select('test', '*', $bind); - ok($stmt eq $_->{stmt} && @bind) or - warn "got\n", - "[$stmt], [@bind]\n", - "instead of\n", - "[$_->{stmt}] [4, 0]\n\n"; + local $" = ', '; + #print "creating a handle with args ($_->{args}): "; + my $sql = SQL::Abstract->new($_->{args}); + my $where = $_->{where} || { a => 4, b => 0}; + my($stmt, @bind) = $sql->select('test', '*', $where); + + # LDNOTE: this original test suite from NWIGER did no comparisons + # on @bind values, just checking if @bind is nonempty. + # So here we just fake a [1] bind value for the comparison. + is_same_sql_bind($stmt, [@bind ? 1 : 0], $_->{stmt}, [1]); }