[Bast-commits] r5710 - SQL-Abstract/1.x/branches/1.50_RC/t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Sun Mar 8 22:37:36 GMT 2009


Author: ribasushi
Date: 2009-03-08 22:37:36 +0000 (Sun, 08 Mar 2009)
New Revision: 5710

Modified:
   SQL-Abstract/1.x/branches/1.50_RC/t/03values.t
Log:
Cleanup test and add a failing test case against RT#43483

Modified: SQL-Abstract/1.x/branches/1.50_RC/t/03values.t
===================================================================
--- SQL-Abstract/1.x/branches/1.50_RC/t/03values.t	2009-03-08 22:31:51 UTC (rev 5709)
+++ SQL-Abstract/1.x/branches/1.50_RC/t/03values.t	2009-03-08 22:37:36 UTC (rev 5710)
@@ -4,12 +4,10 @@
 use warnings;
 use Test::More;
 
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use SQL::Abstract::Test import => [qw/is_same_sql_bind is_same_bind/];
 
 use SQL::Abstract;
 
-my $sql = SQL::Abstract->new;
-
 my @data = (
     {
         user => 'nwiger',
@@ -58,37 +56,52 @@
 );
 
 
-plan tests => scalar(@data);
+plan tests => (@data * 5  +  2);
 
-# Note to self: I have no idea what this does anymore
-# It looks like a cool fucking segment of code though!
-# I just wish I remembered writing it... :-\
+# test insert() and values() for reentrancy
+my($insert_hash, $insert_array, $numfields);
+my $a_sql = SQL::Abstract->new;
+my $h_sql = SQL::Abstract->new;
 
-my($sth, $stmt);
-my($laststmt, $numfields);
-for my $t (@data) {
-      local $"=', ';
+for my $record (@data) {
 
-      $stmt = $sql->insert('yo_table', $t);
-      my @val = $sql->values($t);
-      $numfields ||= @val;
+  my $values = [ map { $record->{$_} } sort keys %$record ];
 
-      ok((! $laststmt || $stmt eq $laststmt) && @val == $numfields
-          && equal(\@val, [map { $t->{$_} } sort keys %$t])) or
-              print "got\n",
-                    "[$stmt] [@val]\n",
-                    "instead of\n",
-                    "[$t->{stmt}] [stuff]\n\n";
-      $laststmt = $stmt;
+  my ($h_stmt, @h_bind) = $h_sql->insert('h_table', $record);
+  my ($a_stmt, @a_bind) = $a_sql->insert('a_table', $values );
+
+  # init from first run, should not change afterwards
+  $insert_hash ||= $h_stmt;
+  $insert_array ||= $a_stmt;
+  $numfields ||= @$values;
+
+  is ( $a_stmt, $insert_array, 'Array-based insert statement unchanged' );
+  is ( $h_stmt, $insert_hash, 'Hash-based insert statement unchanged' );
+
+  is_deeply ( \@a_bind, \@h_bind, 'Bind values match after both insert() calls' );
+  is_deeply ( [$h_sql->values ($record)] , \@h_bind, 'values() output matches bind values after insert()' );
+
+  is ( scalar @h_bind, $numfields, 'Number of fields unchanged' );
 }
 
-sub equal {
-      my ($a, $b) = @_;
-      return 0 if @$a != @$b;
-      for (my $i = 0; $i < $#{$a}; $i++) {
-              next if (! defined($a->[$i])) && (! defined($b->[$i]));
-              return 0 if $a->[$i] ne $b->[$i];
-      }
-      return 1;
+# test values() with literal sql
+{
+  my $sql = SQL::Abstract->new;
+
+  my $data = { event => 'rapture', time => \ 'now()', func => \ 'somefunc(?)', stuff => 'fluff', };
+
+  my ($stmt, @bind) = $sql->insert ('table', $data);
+
+  is_same_sql_bind (
+    $stmt,
+    \@bind,
+    'INSERT INTO table ( event, func, stuff, time) VALUES ( ?, somefunc (?), ?, now() )',
+    [qw/rapture fluff/],  # event < stuff
+  );
+
+  is_same_bind (
+    [$sql->values ($data)],
+    [\@bind],
+    'values() output matches that of initial bind'
+  );
 }
-




More information about the Bast-commits mailing list