10 use Test::More tests => 26;
12 @words = shellwords(qq(foo "bar quiz" zoo));
14 is($words[1], 'bar quiz');
18 # Gonna get some undefined things back
19 no warnings 'uninitialized' ;
21 # Test quotewords() with other parameters and null last field
22 @words = quotewords(':+', 1, 'foo:::"bar:foo":zoo zoo:');
23 is(join(";", @words), qq(foo;"bar:foo";zoo zoo;));
26 # Test $keep eq 'delimiters' and last field zero
27 @words = quotewords('\s+', 'delimiters', '4 3 2 1 0');
28 is(join(";", @words), qq(4; ;3; ;2; ;1; ;0));
30 # Big ol' nasty test (thanks, Joerk!)
31 $string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd" eee\\\\\\"ffff" "gg"';
33 # First with $keep == 1
34 $result = join('|', parse_line('\s+', 1, $string));
35 is($result, '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 # Now test single quote behavior
42 $string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd\' eee\\\\\\"ffff\' gg';
43 $result = join('|', parse_line('\s+', 0, $string));
44 is($result, 'aaaabbbbb|cc cc|\\"dddd eee\\\\\\"ffff|gg');
46 # Make sure @nested_quotewords does the right thing
47 @lists = nested_quotewords('\s+', 0, 'a b c', '1 2 3', 'x y z');
53 # Now test error return
54 $string = 'foo bar baz"bach blech boop';
56 @words = shellwords($string);
59 @words = parse_line('s+', 0, $string);
62 @words = quotewords('s+', 0, $string);
66 # Gonna get some more undefined things back
67 no warnings 'uninitialized' ;
69 @words = nested_quotewords('s+', 0, $string);
72 # Now test empty fields
73 $result = join('|', parse_line(':', 0, 'foo::0:"":::'));
74 is($result, 'foo||0||||');
76 # Test for 0 in quotes without $keep
77 $result = join('|', parse_line(':', 0, ':"0":'));
80 # Test for \001 in quoted string
81 $result = join('|', parse_line(':', 0, ':"' . "\001" . '":'));
86 # Now test perlish single quote behavior
87 $Text::ParseWords::PERL_SINGLE_QUOTE = 1;
88 $string = 'aaaa"bbbbb" cc\ cc \\\\\"dddd\' eee\\\\\"\\\'ffff\' gg';
89 $result = join('|', parse_line('\s+', 0, $string));
90 is($result, 'aaaabbbbb|cc cc|\"dddd eee\\\\"\'ffff|gg');
92 # test whitespace in the delimiters
93 @words = quotewords(' ', 1, '4 3 2 1 0');
94 is(join(";", @words), qq(4;3;2;1;0));
96 # [perl #30442] Text::ParseWords does not handle backslashed newline inside quoted text
97 $string = qq{"field1" "field2\\\nstill field2" "field3"};
99 $result = join('|', parse_line("\t", 1, $string));
100 is($result, qq{"field1"|"field2\\\nstill field2"|"field3"});
102 $result = join('|', parse_line("\t", 0, $string));
103 is($result, "field1|field2\nstill field2|field3");
106 $string = qq{"field1"\x{1234}"field2\\\x{1234}still field2"\x{1234}"field3"};
107 $result = join('|', parse_line("\x{1234}", 0, $string));
108 is($result, "field1|field2\x{1234}still field2|field3");
110 # missing quote after matching regex used to hang after change #22997
111 "1234" =~ /(1)(2)(3)(4)/;
112 $string = qq{"missing quote};
113 $result = join('|', shellwords($string));
116 # make sure shellwords strips out leading whitespace and trailng undefs
117 # from parse_line, so it's behavior is more like /bin/sh
118 $result = join('|', shellwords(" aa \\ \\ bb ", " \\ ", "cc dd ee\\ "));
119 is($result, "aa| | bb| |cc|dd|ee ");