[Bast-commits] r5800 - SQL-Abstract/1.x/trunk/t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Sun Mar 22 23:22:22 GMT 2009


Author: ribasushi
Date: 2009-03-22 23:22:22 +0000 (Sun, 22 Mar 2009)
New Revision: 5800

Modified:
   SQL-Abstract/1.x/trunk/t/04modifiers.t
Log:
More modifier tests, all appear to be good (more needed)

Modified: SQL-Abstract/1.x/trunk/t/04modifiers.t
===================================================================
--- SQL-Abstract/1.x/trunk/t/04modifiers.t	2009-03-22 22:26:12 UTC (rev 5799)
+++ SQL-Abstract/1.x/trunk/t/04modifiers.t	2009-03-22 23:22:22 UTC (rev 5800)
@@ -10,7 +10,7 @@
 use SQL::Abstract;
 
 =begin
-Test -and -or and -nest/-nestX modifiers, assuming the following:
+Test -and -or and -nest modifiers, assuming the following:
 
   * Modifiers are respected in both hashrefs and arrayrefs (with the obvious limitation of one modifier type per hahsref)
   * Each modifier affects only the immediate element following it
@@ -22,19 +22,83 @@
 
 =cut
 
+# no warnings
+my @and_or_tests = (
+  {
+    where => { -and => [a => 1, b => 2] },
+    stmt => 'WHERE a = ? AND b = ?',
+    bind => [qw/1 2/],
+  },
+  {
+    where => [ -and => [a => 1, b => 2] ],
+    stmt => 'WHERE a = ? AND b = ?',
+    bind => [qw/1 2/],
+  },
+  {
+    where => { -or => [a => 1, b => 2] },
+    stmt => 'WHERE a = ? OR b = ?',
+    bind => [qw/1 2/],
+  },
+  {
+    where => [ -or => [a => 1, b => 2] ],
+    stmt => 'WHERE a = ? OR b = ?',
+    bind => [qw/1 2/],
+  },
+  {
+    where => { -and => [a => 1, b => 2], x => 9, -or => { c => 3, d => 4 } },
+    stmt => 'WHERE a = ? AND b = ? AND ( c = ? OR d = ? ) AND x = ?',
+    bind => [qw/1 2 3 4 9/],
+  },
+  {
+    where => { -and => [a => 1, b => 2, k => [11, 12] ], x => 9, -or => { c => 3, d => 4, l => { '=' => [21, 22] } } },
+    stmt => 'WHERE a = ? AND b = ? AND (k = ? OR k = ?) AND ( l = ? OR l = ? OR c = ? OR d = ? ) AND x = ?',
+    bind => [qw/1 2 11 12 21 22 3 4 9/],
+  },
+  {
+    where => { -or => [a => 1, b => 2, k => [11, 12] ], x => 9, -and => { c => 3, d => 4, l => { '=' => [21, 22] } } },
+    stmt => 'WHERE c = ? AND d = ? AND ( l = ? OR l = ?) AND (a = ? OR b = ? OR k = ? OR k = ?) AND x = ?',
+    bind => [qw/3 4 21 22 1 2 11 12 9/],
+  },
 
-my @handle_tests = ();
+  {
+    # things should remain the same as above, hashrefs not affected
+    args => { logic => 'or' },
+    where => { -or => [a => 1, b => 2, k => [11, 12] ], x => 9, -and => { c => 3, d => 4, l => { '=' => [21, 22] } } },
+    stmt => 'WHERE c = ? AND d = ? AND ( l = ? OR l = ?) AND (a = ? OR b = ? OR k = ? OR k = ?) AND x = ?',
+    bind => [qw/3 4 21 22 1 2 11 12 9/],
+  },
 
-plan tests => @handle_tests * 2 + 1;
-ok (1);
+  {
+    where => [ -or => [a => 1, b => 2], -or => { c => 3, d => 4}, e => 5, -and => [ f => 6, g => 7], [ h => 8, i => 9, -and => [ k => 10, l => 11] ], { m => 12, n => 13 }],
+    stmt => 'WHERE a = ? OR b = ? OR c = ? OR d = ? OR e = ? OR ( f = ? AND g = ?) OR h = ? OR i = ? OR ( k = ? AND l = ? ) OR (m = ? AND n = ?)',
+    bind => [1 .. 13],
+  },
+  {
+    # while the arrayref logic should flip, except when requested otherwise
+    args => { logic => 'and' },
+    where => [ -or => [a => 1, b => 2], -or => { c => 3, d => 4}, e => 5, -and => [ f => 6, g => 7], [ h => 8, i => 9, -and => [ k => 10, l => 11] ], { m => 12, n => 13 }],
+    stmt => 'WHERE (a = ? OR b = ?) AND (c = ? OR d = ?) AND e = ? AND f = ? AND g = ? AND h = ? AND i = ? AND k = ? AND l = ? AND m = ? AND n = ?',
+    bind => [1 .. 13],
+  },
+);
 
-for my $case (@handle_tests) {
+my @nest_tests = ();      #can not be verified via is_same_sql_bind - need exact matching (parenthesis and all)
+
+my @numbered_tests = ();  #need tests making sure warnings are emitted for modifierN (will go away in SQLA2)
+
+plan tests => @and_or_tests * 3;
+
+for my $case (@and_or_tests) {
     local $Data::Dumper::Terse = 1;
-    my $sql = SQL::Abstract->new;
-    my($stmt, @bind);
+
+    my @w;
+    local $SIG{__WARN__} = sub { push @w, @_ };
+    my $sql = SQL::Abstract->new ($case->{args} || {});
     lives_ok (sub { 
-      ($stmt, @bind) = $sql->where($case->{where}, $case->{order});
+      my ($stmt, @bind) = $sql->where($case->{where});
       is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind})
         || diag "Search term:\n" . Dumper $case->{where};
     });
+    is (@w, 0, 'No warnings within and-or tests')
+      || diag join "\n", 'Emitted warnings:', @w;
 }




More information about the Bast-commits mailing list