diff options
Diffstat (limited to 't/author-split_like_shell.t')
-rw-r--r-- | t/author-split_like_shell.t | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/t/author-split_like_shell.t b/t/author-split_like_shell.t new file mode 100644 index 0000000..92ab2a3 --- /dev/null +++ b/t/author-split_like_shell.t @@ -0,0 +1,89 @@ +#!/usr/bin/perl + +BEGIN { + unless ($ENV{AUTHOR_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for testing by the author'); + } +} + + +use strict; +use warnings FATAL => 'all'; +use Test::More; +use ExtUtils::Helpers::Unix (); +use ExtUtils::Helpers::Windows (); + +plan(skip_all => 'Author only tests') unless $ENV{AUTHOR_TESTING}; + +my @unix_splits = + ( + { q{one t'wo th'ree f"o\"ur " "five" } => [ 'one', 'two three', 'fo"ur ', 'five' ] }, + { q{ foo bar } => [ 'foo', 'bar' ] }, + { q{ D\'oh f\{g\'h\"i\]\* } => [ "D'oh", "f{g'h\"i]*" ] }, + { q{ D\$foo } => [ 'D$foo' ] }, + { qq{one\\\ntwo} => [ "one\ntwo" ] }, # TODO + ); + +my @win_splits = + ( + { 'a" "b\\c" "d' => [ 'a b\c d' ] }, + { '"a b\\c d"' => [ 'a b\c d' ] }, + { '"a b"\\"c d"' => [ 'a b"c', 'd' ] }, + { '"a b"\\\\"c d"' => [ 'a b\c d' ] }, + { '"a"\\"b" "a\\"b"' => [ 'a"b a"b' ] }, + { '"a"\\\\"b" "a\\\\"b"' => [ 'a\b', 'a\b' ] }, + { '"a"\\"b a\\"b"' => [ 'a"b', 'a"b' ] }, + { 'a"\\"b" "a\\"b' => [ 'a"b', 'a"b' ] }, + { 'a"\\"b" "a\\"b' => [ 'a"b', 'a"b' ] }, + { 'a b' => [ 'a', 'b' ] }, + { "a\nb" => [ 'a', 'b' ] }, + { 'a"\\"b a\\"b' => [ 'a"b a"b' ] }, + { '"a""b" "a"b"' => [ 'a"b ab' ] }, + { '\\"a\\"' => [ '"a"' ] }, + { '"a"" "b"' => [ 'a"', 'b' ] }, + { 'a"b' => [ 'ab' ] }, + { 'a""b' => [ 'ab' ] }, + { 'a"""b' => [ 'a"b' ] }, + { 'a""""b' => [ 'a"b' ] }, + { 'a"""""b' => [ 'a"b' ] }, + { 'a""""""b' => [ 'a""b' ] }, + { '"a"b"' => [ 'ab' ] }, + { '"a""b"' => [ 'a"b' ] }, + { '"a"""b"' => [ 'a"b' ] }, + { '"a""""b"' => [ 'a"b' ] }, + { '"a"""""b"' => [ 'a""b' ] }, + { '"a""""""b"' => [ 'a""b' ] }, + { '' => [ ] }, + { ' ' => [ ] }, + { '""' => [ '' ] }, + { '" "' => [ ' ' ] }, + { '""a' => [ 'a' ] }, + { '""a b' => [ 'a', 'b' ] }, + { 'a""' => [ 'a' ] }, + { 'a"" b' => [ 'a', 'b' ] }, + { '"" a' => [ '', 'a' ] }, + { 'a ""' => [ 'a', '' ] }, + { 'a "" b' => [ 'a', '', 'b' ] }, + { 'a " " b' => [ 'a', ' ', 'b' ] }, + { 'a " b " c' => [ 'a', ' b ', 'c' ] }, +); + +foreach my $test (@win_splits) { + my ($string, $expected) = %$test; + my @result = ExtUtils::Helpers::Windows::split_like_shell($string); + $string =~ s/\n/\\n/g; + is(grep( !defined(), @result ), 0, "\"$string\" result all defined"); + is_deeply(\@result, $expected) or + diag("split_like_shell error \n>$string< is not splitting as >" . join("|", @$expected) . '<'); +} +foreach my $test (@unix_splits) { + my ($string, $expected) = %$test; + my @result = ExtUtils::Helpers::Unix::split_like_shell($string); + $string =~ s/\n/\\n/g; + is(grep( !defined(), @result ), 0, "\"$string\" result all defined"); + is_deeply(\@result, $expected) or + diag("split_like_shell error \n>$string< is not splitting as >" . join("|", @$expected) . '<'); +} + +done_testing; |