Bump the debugger's version. Fail to update the changes.
[p5sagit/p5-mst-13.2.git] / lib / Text / ParseWords.t
index 261d81f..eeee6ee 100755 (executable)
-#!./perl
-
-BEGIN {
-    chdir 't' if -d 't';
-    @INC = '../lib';
-}
-
-use warnings;
-use Text::ParseWords;
-
-print "1..18\n";
-
-@words = shellwords(qq(foo "bar quiz" zoo));
-print "not " if $words[0] ne 'foo';
-print "ok 1\n";
-print "not " if $words[1] ne 'bar quiz';
-print "ok 2\n";
-print "not " if $words[2] ne 'zoo';
-print "ok 3\n";
-
-{
-  # Gonna get some undefined things back
-  no warnings 'uninitialized' ;
-
-  # Test quotewords() with other parameters and null last field
-  @words = quotewords(':+', 1, 'foo:::"bar:foo":zoo zoo:');
-  print "not " unless join(";", @words) eq qq(foo;"bar:foo";zoo zoo;);
-  print "ok 4\n";
-}
-
-# Test $keep eq 'delimiters' and last field zero
-@words = quotewords('\s+', 'delimiters', '4 3 2 1 0');
-print "not " unless join(";", @words) eq qq(4; ;3; ;2; ;1; ;0);
-print "ok 5\n";
-
-# Big ol' nasty test (thanks, Joerk!)
-$string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd" eee\\\\\\"ffff" "gg"';
-
-# First with $keep == 1
-$result = join('|', parse_line('\s+', 1, $string));
-print "not " unless $result eq 'aaaa"bbbbb"|cc\\ cc|\\\\\\"dddd" eee\\\\\\"ffff"|"gg"';
-print "ok 6\n";
-
-# Now, $keep == 0
-$result = join('|', parse_line('\s+', 0, $string));
-print "not " unless $result eq 'aaaabbbbb|cc cc|\\"dddd eee\\"ffff|gg';
-print "ok 7\n";
-
-# Now test single quote behavior
-$string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd\' eee\\\\\\"ffff\' gg';
-$result = join('|', parse_line('\s+', 0, $string));
-print "not " unless $result eq 'aaaabbbbb|cc cc|\\"dddd eee\\\\\\"ffff|gg';
-print "ok 8\n";
-
-# Make sure @nested_quotewords does the right thing
-@lists = nested_quotewords('\s+', 0, 'a b c', '1 2 3', 'x y z');
-print "not " unless (@lists == 3 && @{$lists[0]} == 3 && @{$lists[1]} == 3 && @{$lists[2]} == 3);
-print "ok 9\n";
-
-# Now test error return
-$string = 'foo bar baz"bach blech boop';
-
-@words = shellwords($string);
-print "not " if (@words);
-print "ok 10\n";
-
-@words = parse_line('s+', 0, $string);
-print "not " if (@words);
-print "ok 11\n";
-
-@words = quotewords('s+', 0, $string);
-print "not " if (@words);
-print "ok 12\n";
-
-{
-  # Gonna get some more undefined things back
-  no warnings 'uninitialized' ;
-
-  @words = nested_quotewords('s+', 0, $string);
-  print "not " if (@words);
-  print "ok 13\n";
-
-  # Now test empty fields
-  $result = join('|', parse_line(':', 0, 'foo::0:"":::'));
-  print "not " unless ($result eq 'foo||0||||');
-  print "ok 14\n";
-
-  # Test for 0 in quotes without $keep
-  $result = join('|', parse_line(':', 0, ':"0":'));
-  print "not " unless ($result eq '|0|');
-  print "ok 15\n";
-
-  # Test for \001 in quoted string
-  $result = join('|', parse_line(':', 0, ':"' . "\001" . '":'));
-  print "not " unless ($result eq "|\1|");
-  print "ok 16\n";
-
-}
-
-# Now test perlish single quote behavior
-$Text::ParseWords::PERL_SINGLE_QUOTE = 1;
-$string = 'aaaa"bbbbb" cc\ cc \\\\\"dddd\' eee\\\\\"\\\'ffff\' gg';
-$result = join('|', parse_line('\s+', 0, $string));
-print "not " unless $result eq 'aaaabbbbb|cc cc|\"dddd eee\\\\"\'ffff|gg';
-print "ok 17\n";
-
-# test whitespace in the delimiters
-@words = quotewords(' ', 1, '4 3 2 1 0');
-print "not " unless join(";", @words) eq qq(4;3;2;1;0);
-print "ok 18\n";
+#!./perl\r
+\r
+BEGIN {\r
+    if( $ENV{PERL_CORE} ) {\r
+        chdir 't' if -d 't';\r
+        @INC = '../lib';\r
+    }\r
+}\r
+\r
+use warnings;\r
+use Text::ParseWords;\r
+use Test::More tests => 27;\r
+\r
+@words = shellwords(qq(foo "bar quiz" zoo));\r
+is($words[0], 'foo');\r
+is($words[1], 'bar quiz');\r
+is($words[2], 'zoo');\r
+\r
+{\r
+  # Gonna get some undefined things back\r
+  no warnings 'uninitialized' ;\r
+\r
+  # Test quotewords() with other parameters and null last field\r
+  @words = quotewords(':+', 1, 'foo:::"bar:foo":zoo zoo:');\r
+  is(join(";", @words), qq(foo;"bar:foo";zoo zoo;));\r
+}\r
+\r
+# Test $keep eq 'delimiters' and last field zero\r
+@words = quotewords('\s+', 'delimiters', '4 3 2 1 0');\r
+is(join(";", @words), qq(4; ;3; ;2; ;1; ;0));\r
+\r
+# Big ol' nasty test (thanks, Joerk!)\r
+$string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd" eee\\\\\\"ffff" "gg"';\r
+\r
+# First with $keep == 1\r
+$result = join('|', parse_line('\s+', 1, $string));\r
+is($result, 'aaaa"bbbbb"|cc\\ cc|\\\\\\"dddd" eee\\\\\\"ffff"|"gg"');\r
+\r
+# Now, $keep == 0\r
+$result = join('|', parse_line('\s+', 0, $string));\r
+is($result, 'aaaabbbbb|cc cc|\\"dddd eee\\"ffff|gg');\r
+\r
+# Now test single quote behavior\r
+$string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd\' eee\\\\\\"ffff\' gg';\r
+$result = join('|', parse_line('\s+', 0, $string));\r
+is($result, 'aaaabbbbb|cc cc|\\"dddd eee\\\\\\"ffff|gg');\r
+\r
+# Make sure @nested_quotewords does the right thing\r
+@lists = nested_quotewords('\s+', 0, 'a b c', '1 2 3', 'x y z');\r
+is (@lists, 3);\r
+is (@{$lists[0]}, 3);\r
+is (@{$lists[1]}, 3);\r
+is (@{$lists[2]}, 3);\r
+\r
+# Now test error return\r
+$string = 'foo bar baz"bach blech boop';\r
+\r
+@words = shellwords($string);\r
+is(@words, 0);\r
+\r
+@words = parse_line('s+', 0, $string);\r
+is(@words, 0);\r
+\r
+@words = quotewords('s+', 0, $string);\r
+is(@words, 0);\r
+\r
+{\r
+  # Gonna get some more undefined things back\r
+  no warnings 'uninitialized' ;\r
+\r
+  @words = nested_quotewords('s+', 0, $string);\r
+  is(@words, 0);\r
+\r
+  # Now test empty fields\r
+  $result = join('|', parse_line(':', 0, 'foo::0:"":::'));\r
+  is($result, 'foo||0||||');\r
+\r
+  # Test for 0 in quotes without $keep\r
+  $result = join('|', parse_line(':', 0, ':"0":'));\r
+  is($result, '|0|');\r
+\r
+  # Test for \001 in quoted string\r
+  $result = join('|', parse_line(':', 0, ':"' . "\001" . '":'));\r
+  is($result, "|\1|");\r
+\r
+}\r
+\r
+# Now test perlish single quote behavior\r
+$Text::ParseWords::PERL_SINGLE_QUOTE = 1;\r
+$string = 'aaaa"bbbbb" cc\ cc \\\\\"dddd\' eee\\\\\"\\\'ffff\' gg';\r
+$result = join('|', parse_line('\s+', 0, $string));\r
+is($result, 'aaaabbbbb|cc cc|\"dddd eee\\\\"\'ffff|gg');\r
+\r
+# test whitespace in the delimiters\r
+@words = quotewords(' ', 1, '4 3 2 1 0');\r
+is(join(";", @words), qq(4;3;2;1;0));\r
+\r
+# [perl #30442] Text::ParseWords does not handle backslashed newline inside quoted text\r
+$string = qq{"field1"  "field2\\\nstill field2"        "field3"};\r
+\r
+$result = join('|', parse_line("\t", 1, $string));\r
+is($result, qq{"field1"|"field2\\\nstill field2"|"field3"});\r
+\r
+$result = join('|', parse_line("\t", 0, $string));\r
+is($result, "field1|field2\nstill field2|field3");\r
+\r
+SKIP: { # unicode\r
+  skip "No unicode",1 if $]<5.008;\r
+  $string = qq{"field1"\x{1234}"field2\\\x{1234}still field2"\x{1234}"field3"};\r
+  $result = join('|', parse_line("\x{1234}", 0, $string));\r
+  is($result, "field1|field2\x{1234}still field2|field3",'Unicode');\r
+}\r
+\r
+# missing quote after matching regex used to hang after change #22997\r
+"1234" =~ /(1)(2)(3)(4)/;\r
+$string = qq{"missing quote};\r
+$result = join('|', shellwords($string));\r
+is($result, "");\r
+\r
+# make sure shellwords strips out leading whitespace and trailng undefs\r
+# from parse_line, so it's behavior is more like /bin/sh\r
+$result = join('|', shellwords(" aa \\  \\ bb ", " \\  ", "cc dd ee\\ "));\r
+is($result, "aa| | bb| |cc|dd|ee ");\r
+\r
+$SIG{ALRM} = sub {die "Timeout!"};\r
+alarm(3);\r
+@words = Text::ParseWords::old_shellwords("foo\\");\r
+is(@words, 1);\r
+alarm(0);\r