5 use Test::More tests => 27;
7 @words = shellwords(qq(foo "bar quiz" zoo));
9 is($words[1], 'bar quiz');
13 # Gonna get some undefined things back
14 no warnings 'uninitialized' ;
16 # Test quotewords() with other parameters and null last field
17 @words = quotewords(':+', 1, 'foo:::"bar:foo":zoo zoo:');
18 is(join(";", @words), qq(foo;"bar:foo";zoo zoo;));
21 # Test $keep eq 'delimiters' and last field zero
22 @words = quotewords('\s+', 'delimiters', '4 3 2 1 0');
23 is(join(";", @words), qq(4; ;3; ;2; ;1; ;0));
25 # Big ol' nasty test (thanks, Joerk!)
26 $string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd" eee\\\\\\"ffff" "gg"';
28 # First with $keep == 1
29 $result = join('|', parse_line('\s+', 1, $string));
30 is($result, 'aaaa"bbbbb"|cc\\ cc|\\\\\\"dddd" eee\\\\\\"ffff"|"gg"');
33 $result = join('|', parse_line('\s+', 0, $string));
34 is($result, 'aaaabbbbb|cc cc|\\"dddd eee\\"ffff|gg');
36 # Now test single quote behavior
37 $string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd\' eee\\\\\\"ffff\' gg';
38 $result = join('|', parse_line('\s+', 0, $string));
39 is($result, 'aaaabbbbb|cc cc|\\"dddd eee\\\\\\"ffff|gg');
41 # Make sure @nested_quotewords does the right thing
42 @lists = nested_quotewords('\s+', 0, 'a b c', '1 2 3', 'x y z');
48 # Now test error return
49 $string = 'foo bar baz"bach blech boop';
51 @words = shellwords($string);
54 @words = parse_line('s+', 0, $string);
57 @words = quotewords('s+', 0, $string);
61 # Gonna get some more undefined things back
62 no warnings 'uninitialized' ;
64 @words = nested_quotewords('s+', 0, $string);
67 # Now test empty fields
68 $result = join('|', parse_line(':', 0, 'foo::0:"":::'));
69 is($result, 'foo||0||||');
71 # Test for 0 in quotes without $keep
72 $result = join('|', parse_line(':', 0, ':"0":'));
75 # Test for \001 in quoted string
76 $result = join('|', parse_line(':', 0, ':"' . "\001" . '":'));
81 # Now test perlish single quote behavior
82 $Text::ParseWords::PERL_SINGLE_QUOTE = 1;
83 $string = 'aaaa"bbbbb" cc\ cc \\\\\"dddd\' eee\\\\\"\\\'ffff\' gg';
84 $result = join('|', parse_line('\s+', 0, $string));
85 is($result, 'aaaabbbbb|cc cc|\"dddd eee\\\\"\'ffff|gg');
87 # test whitespace in the delimiters
88 @words = quotewords(' ', 1, '4 3 2 1 0');
89 is(join(";", @words), qq(4;3;2;1;0));
91 # [perl #30442] Text::ParseWords does not handle backslashed newline inside quoted text
92 $string = qq{"field1" "field2\\\nstill field2" "field3"};
94 $result = join('|', parse_line("\t", 1, $string));
95 is($result, qq{"field1"|"field2\\\nstill field2"|"field3"});
97 $result = join('|', parse_line("\t", 0, $string));
98 is($result, "field1|field2\nstill field2|field3");
101 skip "No unicode",1 if $]<5.008;
102 $string = qq{"field1"\x{1234}"field2\\\x{1234}still field2"\x{1234}"field3"};
103 $result = join('|', parse_line("\x{1234}", 0, $string));
104 is($result, "field1|field2\x{1234}still field2|field3",'Unicode');
107 # missing quote after matching regex used to hang after change #22997
108 "1234" =~ /(1)(2)(3)(4)/;
109 $string = qq{"missing quote};
110 $result = join('|', shellwords($string));
113 # make sure shellwords strips out leading whitespace and trailng undefs
114 # from parse_line, so it's behavior is more like /bin/sh
115 $result = join('|', shellwords(" aa \\ \\ bb ", " \\ ", "cc dd ee\\ "));
116 is($result, "aa| | bb| |cc|dd|ee ");
118 $SIG{ALRM} = sub {die "Timeout!"};
120 @words = Text::ParseWords::old_shellwords("foo\\");