1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A}
1N/A
1N/Ause warnings;
1N/Ause Text::ParseWords;
1N/A
1N/Aprint "1..18\n";
1N/A
1N/A@words = shellwords(qq(foo "bar quiz" zoo));
1N/Aprint "not " if $words[0] ne 'foo';
1N/Aprint "ok 1\n";
1N/Aprint "not " if $words[1] ne 'bar quiz';
1N/Aprint "ok 2\n";
1N/Aprint "not " if $words[2] ne 'zoo';
1N/Aprint "ok 3\n";
1N/A
1N/A{
1N/A # Gonna get some undefined things back
1N/A no warnings 'uninitialized' ;
1N/A
1N/A # Test quotewords() with other parameters and null last field
1N/A @words = quotewords(':+', 1, 'foo:::"bar:foo":zoo zoo:');
1N/A print "not " unless join(";", @words) eq qq(foo;"bar:foo";zoo zoo;);
1N/A print "ok 4\n";
1N/A}
1N/A
1N/A# Test $keep eq 'delimiters' and last field zero
1N/A@words = quotewords('\s+', 'delimiters', '4 3 2 1 0');
1N/Aprint "not " unless join(";", @words) eq qq(4; ;3; ;2; ;1; ;0);
1N/Aprint "ok 5\n";
1N/A
1N/A# Big ol' nasty test (thanks, Joerk!)
1N/A$string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd" eee\\\\\\"ffff" "gg"';
1N/A
1N/A# First with $keep == 1
1N/A$result = join('|', parse_line('\s+', 1, $string));
1N/Aprint "not " unless $result eq 'aaaa"bbbbb"|cc\\ cc|\\\\\\"dddd" eee\\\\\\"ffff"|"gg"';
1N/Aprint "ok 6\n";
1N/A
1N/A# Now, $keep == 0
1N/A$result = join('|', parse_line('\s+', 0, $string));
1N/Aprint "not " unless $result eq 'aaaabbbbb|cc cc|\\"dddd eee\\"ffff|gg';
1N/Aprint "ok 7\n";
1N/A
1N/A# Now test single quote behavior
1N/A$string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd\' eee\\\\\\"ffff\' gg';
1N/A$result = join('|', parse_line('\s+', 0, $string));
1N/Aprint "not " unless $result eq 'aaaabbbbb|cc cc|\\"dddd eee\\\\\\"ffff|gg';
1N/Aprint "ok 8\n";
1N/A
1N/A# Make sure @nested_quotewords does the right thing
1N/A@lists = nested_quotewords('\s+', 0, 'a b c', '1 2 3', 'x y z');
1N/Aprint "not " unless (@lists == 3 && @{$lists[0]} == 3 && @{$lists[1]} == 3 && @{$lists[2]} == 3);
1N/Aprint "ok 9\n";
1N/A
1N/A# Now test error return
1N/A$string = 'foo bar baz"bach blech boop';
1N/A
1N/A@words = shellwords($string);
1N/Aprint "not " if (@words);
1N/Aprint "ok 10\n";
1N/A
1N/A@words = parse_line('s+', 0, $string);
1N/Aprint "not " if (@words);
1N/Aprint "ok 11\n";
1N/A
1N/A@words = quotewords('s+', 0, $string);
1N/Aprint "not " if (@words);
1N/Aprint "ok 12\n";
1N/A
1N/A{
1N/A # Gonna get some more undefined things back
1N/A no warnings 'uninitialized' ;
1N/A
1N/A @words = nested_quotewords('s+', 0, $string);
1N/A print "not " if (@words);
1N/A print "ok 13\n";
1N/A
1N/A # Now test empty fields
1N/A $result = join('|', parse_line(':', 0, 'foo::0:"":::'));
1N/A print "not " unless ($result eq 'foo||0||||');
1N/A print "ok 14\n";
1N/A
1N/A # Test for 0 in quotes without $keep
1N/A $result = join('|', parse_line(':', 0, ':"0":'));
1N/A print "not " unless ($result eq '|0|');
1N/A print "ok 15\n";
1N/A
1N/A # Test for \001 in quoted string
1N/A $result = join('|', parse_line(':', 0, ':"' . "\001" . '":'));
1N/A print "not " unless ($result eq "|\1|");
1N/A print "ok 16\n";
1N/A
1N/A}
1N/A
1N/A# Now test perlish single quote behavior
1N/A$Text::ParseWords::PERL_SINGLE_QUOTE = 1;
1N/A$string = 'aaaa"bbbbb" cc\ cc \\\\\"dddd\' eee\\\\\"\\\'ffff\' gg';
1N/A$result = join('|', parse_line('\s+', 0, $string));
1N/Aprint "not " unless $result eq 'aaaabbbbb|cc cc|\"dddd eee\\\\"\'ffff|gg';
1N/Aprint "ok 17\n";
1N/A
1N/A# test whitespace in the delimiters
1N/A@words = quotewords(' ', 1, '4 3 2 1 0');
1N/Aprint "not " unless join(";", @words) eq qq(4;3;2;1;0);
1N/Aprint "ok 18\n";