Fixed the problem with values() not behaving the same as the rest of the code.
[dbsrgits/SQL-Abstract.git] / t / 02where.t
index b279651..94ce7d5 100644 (file)
@@ -4,19 +4,16 @@ use strict;
 use warnings;
 use Test::More;
 use Test::Exception;
-
-use FindBin;
-use lib "$FindBin::Bin";
-use TestSqlAbstract;
-
-plan tests => 15;
+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',
@@ -30,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'
@@ -178,16 +184,46 @@ 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 = ? ) )",
+       bind => [ 1 ],
+   },
+
+   {
+       where => { foo => $not_stringifiable, },
+       stmt => " WHERE ( foo = ? )",
+       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 => { '>=' => [] }},);
-}
+};