12 @words = shellwords(qq(foo "bar quiz" zoo));
13 print "not " if $words[0] ne 'foo';
15 print "not " if $words[1] ne 'bar quiz';
17 print "not " if $words[2] ne 'zoo';
20 # Gonna get some undefined things back
23 # Test quotewords() with other parameters and null last field
24 @words = quotewords(':+', 1, 'foo:::"bar:foo":zoo zoo:');
25 print "not " unless join(";", @words) eq qq(foo;"bar:foo";zoo zoo;);
30 # Test $keep eq 'delimiters' and last field zero
31 @words = quotewords('\s+', 'delimiters', '4 3 2 1 0');
32 print "not " unless join(";", @words) eq qq(4; ;3; ;2; ;1; ;0);
35 # Big ol' nasty test (thanks, Joerk!)
36 $string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd" eee\\\\\\"ffff" "gg"';
38 # First with $keep == 1
39 $result = join('|', parse_line('\s+', 1, $string));
40 print "not " unless $result eq 'aaaa"bbbbb"|cc\\ cc|\\\\\\"dddd" eee\\\\\\"ffff"|"gg"';
44 $result = join('|', parse_line('\s+', 0, $string));
45 print "not " unless $result eq 'aaaabbbbb|cc cc|\\"dddd eee\\"ffff|gg';
48 # Now test single quote behavior
49 $string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd\' eee\\\\\\"ffff\' gg';
50 $result = join('|', parse_line('\s+', 0, $string));
51 print "not " unless $result eq 'aaaabbbbb|cc cc|\\"dddd eee\\\\\\"ffff|gg';
54 # Make sure @nested_quotewords does the right thing
55 @lists = nested_quotewords('\s+', 0, 'a b c', '1 2 3', 'x y z');
56 print "not " unless (@lists == 3 && @{$lists[0]} == 3 && @{$lists[1]} == 3 && @{$lists[2]} == 3);
59 # Now test error return
60 $string = 'foo bar baz"bach blech boop';
62 @words = shellwords($string);
63 print "not " if (@words);
66 @words = parse_line('s+', 0, $string);
67 print "not " if (@words);
70 @words = quotewords('s+', 0, $string);
71 print "not " if (@words);
74 # Gonna get some more undefined things back
77 @words = nested_quotewords('s+', 0, $string);
78 print "not " if (@words);
81 # Now test empty fields
82 $result = join('|', parse_line(':', 0, 'foo::0:"":::'));
83 print "not " unless ($result eq 'foo||0||||');
86 # Test for 0 in quotes without $keep
87 $result = join('|', parse_line(':', 0, ':"0":'));
88 print "not " unless ($result eq '|0|');
91 # Test for \001 in quoted string
92 $result = join('|', parse_line(':', 0, ':"' . "\001" . '":'));
93 print "not " unless ($result eq "|\1|");
98 # Now test perlish single quote behavior
99 $Text::ParseWords::PERL_SINGLE_QUOTE = 1;
100 $string = 'aaaa"bbbbb" cc\ cc \\\\\"dddd\' eee\\\\\"\\\'ffff\' gg';
101 $result = join('|', parse_line('\s+', 0, $string));
102 print "not " unless $result eq 'aaaabbbbb|cc cc|\"dddd eee\\\\"\'ffff|gg';