more test cases for splitting lines
John Napiorkowski [Fri, 12 Jun 2009 14:40:31 +0000 (14:40 +0000)]
lib/DBIx/Class/Storage/DBI.pm
t/105-run-file-against-storage.t

index 1ca8d4e..d3cb96c 100644 (file)
@@ -2097,15 +2097,6 @@ sub _normalize_lines {
 Given a string, returns all the individual SQL statements in that String
 as an Array.
 
-my $maybe_quoted = qr/
-"[^"]+"
-|
-'[^']+'
-|
-.+?(?=$deliminator)
-/;
-
-my @parts = ($line=~m/$maybe_quoted*?$deliminator/g);
 
 =cut
 
@@ -2121,6 +2112,21 @@ sub _split_line_into_statements {
   return @parts;
 }
 
+sub _split_line_into_statements_new {
+  my ($self, $line) = @_;
+  my $deliminator=qr{;|$};
+  my $maybe_quoted = qr/
+    "[^"]+"
+    |
+    '[^']+'
+    |
+    .+?(?=$deliminator)
+  /;
+
+  return ($line=~m/$maybe_quoted*?$deliminator/g);
+}
+
+
 =head2 _normalize_statements_from_lines 
 
   my @statements = $storage->_normalize_statements_from_lines(@lines)
index f114638..eb290df 100644 (file)
@@ -1,5 +1,5 @@
 
-use Test::More tests => 12; 
+use Test::More tests => 16; 
 use Test::Exception;
 use lib qw(t/lib);
 
@@ -122,4 +122,21 @@ lives_ok {
 } 'executed statement';
 
 ok $schema->storage->run_file_against_storage(qw/t share simple.sql/), 'executed the simple';
-ok $schema->storage->run_file_against_storage(qw/t share killer.sql/), 'executed the killer';
\ No newline at end of file
+ok $schema->storage->run_file_against_storage(qw/t share killer.sql/), 'executed the killer';
+
+my $storage = $schema->storage;
+
+is_deeply [$storage->_split_line_into_statements("aaa;bbb;ccc")],["aaa;", "bbb;", "ccc", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements("aaa;'bb1;bb2';ccc")],["aaa;", "'bb1;bb2';", "ccc", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements(qq[aaa;"bb1;bb2";ccc])],["aaa;", '"bb1;bb2";', "ccc", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements("aaa;bbb;ccc;")],["aaa;", "bbb;", "ccc;", ""],
+ "Correctly split";
+
+use Data::Dump qw/dump/;
+warn dump $schema->storage->_split_line_into_statements_new("aaa;bbb;ccc");