rename list node type to tuple
[dbsrgits/SQL-Abstract.git] / t / 05in_between.t
index fc3aa1d..2b6c8c7 100644 (file)
@@ -174,6 +174,17 @@ my @in_between_tests = (
     bind => [],
     test => '-in multi-line subquery test',
   },
+
+  # check that the outer paren opener is not too agressive
+  # note: this syntax *is not legal* on SQLite (maybe others)
+  #       see end of https://rt.cpan.org/Ticket/Display.html?id=99503
+  {
+    where => { foo => { -in => \ '(SELECT 1) UNION (SELECT 2)' } },
+    stmt => 'WHERE foo IN ( (SELECT 1) UNION (SELECT 2) )',
+    bind => [],
+    test => '-in paren-opening works on balanced pairs only',
+  },
+
   {
     where => {
       customer => { -in => \[
@@ -268,10 +279,18 @@ my @in_between_tests = (
   },
 
   {
-    where => { -in => [42] },
-    throws => qr/Illegal use of top-level '-in'/,
+    where => { -in => [ 'bob', 4, 2 ] },
+    stmt => ' WHERE (bob IN (?, ?))',
+    bind => [ 4, 2 ],
     test => 'Top level -in',
   },
+# This works but then SQL::Abstract::Tree breaks - something for a later commit
+#  {
+#    where => { -in => [ { -list => [ qw(x y) ] }, { -list => [ 1, 3 ] }, { -list => [ 2, 4 ] } ] },
+#    stmt => ' WHERE ((x, y) IN ((?, ?), (?, ?))',
+#    bind => [ 1, 3, 2, 4 ],
+#    test => 'Top level -in with list args',
+#  },
   {
     where => { -between => [42, 69] },
     throws => qr/Illegal use of top-level '-between'/,
@@ -285,7 +304,7 @@ for my $case (@in_between_tests) {
     local $SQL::Abstract::Test::parenthesis_significant = $case->{parenthesis_significant};
     my $label = $case->{test} || 'in-between test';
 
-    my $sql = SQL::Abstract->new ($case->{args} || {});
+    my $sql = SQL::Abstract->new($case->{args} || {});
 
     if (my $e = $case->{throws}) {
       my $stmt;
@@ -304,7 +323,7 @@ for my $case (@in_between_tests) {
         $case->{stmt},
         $case->{bind},
         "$label generates correct SQL and bind",
-      ) || diag_where ( $case->{where} );
+      ) || diag dumper ({ where => $case->{where}, exp => $sql->_expand_expr($case->{where}) });
     }
   }
 }