Converted all test cases where the tests are queued in an array to calculate the...
[scpubgit/Q-Branch.git] / t / 02where.t
index 3e9e649..85a0e8b 100644 (file)
@@ -4,15 +4,15 @@ use strict;
 use warnings;
 use Test::More;
 use Test::Exception;
-
-use SQL::Abstract::Test qw/is_same_sql_bind/;
-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 $not_stringifiable = SQLA::NotStringifiable->new();
+
 my @handle_tests = (
     {
         where => {
@@ -176,8 +176,29 @@ my @handle_tests = (
         bind => [44, 55, 22, 33],
     },
 
+   {
+       where => { -and => [{}, { 'me.id' => '1'}] },
+       stmt => " WHERE ( ( me.id = ? ) )",
+       bind => [ 1 ],
+   },
+
+   {
+       where => { foo => SQLA::FourtyTwo->new(), },
+       stmt => " WHERE ( foo = ? )",
+       bind => [ 'The Life, the Universe and Everything.' ],
+   },
+
+   {
+       where => { foo => $not_stringifiable, },
+       stmt => " WHERE ( foo = ? )",
+       bind => [ $not_stringifiable ],
+   },
+
 );
 
+
+plan tests => scalar(@handle_tests) + 1;
+
 for my $case (@handle_tests) {
     my $sql = SQL::Abstract->new;
     my($stmt, @bind) = $sql->where($case->{where}, $case->{order});
@@ -187,4 +208,43 @@ for my $case (@handle_tests) {
 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;
+
+
+#======================================================================
+package SQLA::NotStringifiable; # testing stringification of arguments
+#======================================================================
+
+use strict;
+use warnings;
+
+sub new
+{
+  bless {}, shift;
+}
+
+1;