Port tests and extra operator from master 40f2f231
[dbsrgits/SQL-Abstract.git] / t / 01generate.t
index f876e60..72bdd6c 100644 (file)
@@ -554,6 +554,13 @@ my @tests = (
       },
       {
               func => 'select',
+              args => ['test', '*', { a => { -in => [] }, b => { -not_in => [] } }],
+              stmt => 'SELECT * FROM test WHERE ( 0=1 AND 1=1 )',
+              stmt_q => 'SELECT * FROM `test` WHERE ( 0=1 AND 1=1 )',
+              bind => [],
+      },
+      {
+              func => 'select',
               args => ['test', '*', { a => { -in => [42, undef] }, b => { -not_in => [42, undef] } } ],
               stmt => 'SELECT * FROM test WHERE ( ( a IN ( ? ) OR a IS NULL ) AND b NOT IN ( ? ) AND b IS NOT NULL )',
               stmt_q => 'SELECT * FROM `test` WHERE ( ( `a` IN ( ? ) OR `a` IS NULL ) AND `b` NOT IN ( ? ) AND `b` IS NOT NULL )',
@@ -594,8 +601,32 @@ my @tests = (
               stmt_q => 'SELECT * FROM `test` WHERE ( `a` IS NOT  NULL AND `b` IS NOT  NULL )',
               bind => [],
       },
+      {
+              func => 'select',
+              args => ['test', '*', { a => { -in => undef } }],
+              exception_like => qr/Argument passed to the 'IN' operator can not be undefined/,
+      },
 );
 
+# check is( not) => undef
+for my $op ( qw(not is is_not), 'is not' ) {
+  (my $sop = uc $op) =~ s/_/ /gi;
+
+  $sop = 'IS NOT' if $sop eq 'NOT';
+
+  for my $uc (0, 1) {
+    for my $prefix ('', '-') {
+      push @tests, {
+        func => 'where',
+        args => [{ a => { ($prefix . ($uc ? uc $op : lc $op) ) => undef } }],
+        stmt => "WHERE a $sop NULL",
+        stmt_q => "WHERE `a` $sop NULL",
+        bind => [],
+      };
+    }
+  }
+}
+
 for my $t (@tests) {
   local $"=', ';
 
@@ -636,6 +667,7 @@ for my $t (@tests) {
               .Dumper($t)."Exception was: $@";
         }
       }
+
       is_same_sql_bind(
         $stmt,
         \@bind,