13 @words = shellwords(qq(foo "bar quiz" zoo));
14 print "not " if $words[0] ne 'foo';
16 print "not " if $words[1] ne 'bar quiz';
18 print "not " if $words[2] ne 'zoo';
22 # Gonna get some undefined things back
23 no warnings 'uninitialized' ;
25 # Test quotewords() with other parameters and null last field
26 @words = quotewords(':+', 1, 'foo:::"bar:foo":zoo zoo:');
27 print "not " unless join(";", @words) eq qq(foo;"bar:foo";zoo zoo;);
31 # Test $keep eq 'delimiters' and last field zero
32 @words = quotewords('\s+', 'delimiters', '4 3 2 1 0');
33 print "not " unless join(";", @words) eq qq(4; ;3; ;2; ;1; ;0);
36 # Big ol' nasty test (thanks, Joerk!)
37 $string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd" eee\\\\\\"ffff" "gg"';
39 # First with $keep == 1
40 $result = join('|', parse_line('\s+', 1, $string));
41 print "not " unless $result eq 'aaaa"bbbbb"|cc\\ cc|\\\\\\"dddd" eee\\\\\\"ffff"|"gg"';
45 $result = join('|', parse_line('\s+', 0, $string));
46 print "not " unless $result eq 'aaaabbbbb|cc cc|\\"dddd eee\\"ffff|gg';
49 # Now test single quote behavior
50 $string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd\' eee\\\\\\"ffff\' gg';
51 $result = join('|', parse_line('\s+', 0, $string));
52 print "not " unless $result eq 'aaaabbbbb|cc cc|\\"dddd eee\\\\\\"ffff|gg';
55 # Make sure @nested_quotewords does the right thing
56 @lists = nested_quotewords('\s+', 0, 'a b c', '1 2 3', 'x y z');
57 print "not " unless (@lists == 3 && @{$lists[0]} == 3 && @{$lists[1]} == 3 && @{$lists[2]} == 3);
60 # Now test error return
61 $string = 'foo bar baz"bach blech boop';
63 @words = shellwords($string);
64 print "not " if (@words);
67 @words = parse_line('s+', 0, $string);
68 print "not " if (@words);
71 @words = quotewords('s+', 0, $string);
72 print "not " if (@words);
76 # Gonna get some more undefined things back
77 no warnings 'uninitialized' ;
79 @words = nested_quotewords('s+', 0, $string);
80 print "not " if (@words);
83 # Now test empty fields
84 $result = join('|', parse_line(':', 0, 'foo::0:"":::'));
85 print "not " unless ($result eq 'foo||0||||');
88 # Test for 0 in quotes without $keep
89 $result = join('|', parse_line(':', 0, ':"0":'));
90 print "not " unless ($result eq '|0|');
93 # Test for \001 in quoted string
94 $result = join('|', parse_line(':', 0, ':"' . "\001" . '":'));
95 print "not " unless ($result eq "|\1|");
100 # Now test perlish single quote behavior
101 $Text::ParseWords::PERL_SINGLE_QUOTE = 1;
102 $string = 'aaaa"bbbbb" cc\ cc \\\\\"dddd\' eee\\\\\"\\\'ffff\' gg';
103 $result = join('|', parse_line('\s+', 0, $string));
104 print "not " unless $result eq 'aaaabbbbb|cc cc|\"dddd eee\\\\"\'ffff|gg';
107 # test whitespace in the delimiters
108 @words = quotewords(' ', 1, '4 3 2 1 0');
109 print "not " unless join(";", @words) eq qq(4;3;2;1;0);