From: John Napiorkowski Date: Fri, 12 Jun 2009 14:40:31 +0000 (+0000) Subject: more test cases for splitting lines X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f28a35232fafa2449fc5cdf153f804f16f4a6aa3;p=dbsrgits%2FDBIx-Class-Historic.git more test cases for splitting lines --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 1ca8d4e..d3cb96c 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -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) diff --git a/t/105-run-file-against-storage.t b/t/105-run-file-against-storage.t index f114638..eb290df 100644 --- a/t/105-run-file-against-storage.t +++ b/t/105-run-file-against-storage.t @@ -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");