X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F02where.t;h=94ce7d5fd06a787c72b3bf930fdd527561b0b321;hb=bab725ceb3539ee6cff3afba859ec296625a2f9b;hp=331ffd06434aabd0f544502082e52d669e015803;hpb=fffe6900cc1ab24696c060ecfa36d626e84b8bbf;p=dbsrgits%2FSQL-Abstract.git diff --git a/t/02where.t b/t/02where.t index 331ffd0..94ce7d5 100644 --- a/t/02where.t +++ b/t/02where.t @@ -4,16 +4,16 @@ use strict; use warnings; use Test::More; use Test::Exception; -use SQL::Abstract::Test qw/is_same_sql_bind/; - -plan tests => 17; +use SQL::Abstract::Test import => ['is_same_sql_bind']; use SQL::Abstract; # Make sure to test the examples, since having them break is somewhat # embarrassing. :-( -my @handle_tests = ( +my $not_stringifiable = bless {}, 'SQLA::NotStringifiable'; + +my@x=( { where => { requestor => 'inna', @@ -27,6 +27,15 @@ my @handle_tests = ( }, { + where => [ + status => 'completed', + user => 'nwiger', + ], + stmt => " WHERE ( status = ? OR user = ? )", + bind => [qw/completed nwiger/], + }, + + { where => { user => 'nwiger', status => 'completed' @@ -175,7 +184,6 @@ my @handle_tests = ( stmt => " WHERE ( (bar > ? AND bar < ?) AND foo IN (?, ?) )", bind => [44, 55, 22, 33], }, - { where => { -and => [{}, { 'me.id' => '1'}] }, stmt => " WHERE ( ( me.id = ? ) )", @@ -183,45 +191,39 @@ my @handle_tests = ( }, { - where => { foo => SQLA::FourtyTwo->new(), }, + where => { foo => $not_stringifiable, }, stmt => " WHERE ( foo = ? )", - bind => [ 'The Life, the Universe and Everything.' ], + bind => [ $not_stringifiable ], }, +);my @handle_tests = ( + { + where => \[ 'foo ?','bar' ], + stmt => " WHERE (foo = ?)", + bind => [ "bar" ], + }, +);my@x2=( + { + where => [ \[ 'foo ?','bar' ] ], + stmt => " WHERE (foo = ?)", + bind => [ "bar" ], + }, ); + +plan tests => ( @handle_tests * 2 ) + 1; + for my $case (@handle_tests) { my $sql = SQL::Abstract->new; - my($stmt, @bind) = $sql->where($case->{where}, $case->{order}); - is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind}) + my($stmt, @bind); + lives_ok (sub { + ($stmt, @bind) = $sql->where($case->{where}, $case->{order}); + is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind}); + }); } dies_ok { my $sql = SQL::Abstract->new; $sql->where({ foo => { '>=' => [] }},); }; - - - -#====================================================================== -package SQLA::FourtyTwo; # testing stringification of arguments -#====================================================================== - -use strict; -use warnings; - -use overload - '""' => \&to_str; - -sub new -{ - bless {}, shift; -} - -sub to_str -{ - return "The Life, the Universe and Everything."; -} - -1;