Commit | Line | Data |
---|---|---|
1a3850a5 GA |
1 | #!./perl |
2 | ||
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
5 | @INC = '../lib'; | |
6 | } | |
7 | ||
1a3850a5 GA |
8 | use Text::ParseWords; |
9 | ||
9b599b2a | 10 | print "1..15\n"; |
1a3850a5 | 11 | |
9b599b2a | 12 | @words = shellwords(qq(foo "bar quiz" zoo)); |
1a3850a5 GA |
13 | print "not " if $words[0] ne 'foo'; |
14 | print "ok 1\n"; | |
1a3850a5 GA |
15 | print "not " if $words[1] ne 'bar quiz'; |
16 | print "ok 2\n"; | |
1a3850a5 GA |
17 | print "not " if $words[2] ne 'zoo'; |
18 | print "ok 3\n"; | |
19 | ||
9b599b2a GS |
20 | # Test quotewords() with other parameters and null last field |
21 | @words = quotewords(':+', 1, 'foo:::"bar:foo":zoo zoo:'); | |
22 | print "not " unless join(";", @words) eq qq(foo;"bar:foo";zoo zoo;); | |
1a3850a5 | 23 | print "ok 4\n"; |
9b599b2a GS |
24 | |
25 | # Test $keep eq 'delimiters' and last field zero | |
26 | @words = quotewords('\s+', 'delimiters', '4 3 2 1 0'); | |
27 | print "not " unless join(";", @words) eq qq(4; ;3; ;2; ;1; ;0); | |
28 | print "ok 5\n"; | |
29 | ||
30 | # Big ol' nasty test (thanks, Joerk!) | |
31 | $string = 'aaaa"bbbbb" cc\\ cc \\\\\\"dddd" eee\\\\\\"ffff" "gg"'; | |
32 | ||
33 | # First with $keep == 1 | |
34 | $result = join('|', parse_line('\s+', 1, $string)); | |
35 | print "not " unless $result eq 'aaaa"bbbbb"|cc\\ cc|\\\\\\"dddd" eee\\\\\\"ffff"|"gg"'; | |
36 | print "ok 6\n"; | |
37 | ||
38 | # Now, $keep == 0 | |
39 | $result = join('|', parse_line('\s+', 0, $string)); | |
40 | print "not " unless $result eq 'aaaabbbbb|cc cc|\\"dddd eee\\"ffff|gg'; | |
41 | print "ok 7\n"; | |
42 | ||
43 | # Now test single quote behavior | |
44 | $string = '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'; | |
47 | print "ok 8\n"; | |
48 | ||
49 | # Make sure @nested_quotewords does the right thing | |
50 | @lists = nested_quotewords('\s+', 0, 'a b c', '1 2 3', 'x y z'); | |
51 | print "not " unless (@lists == 3 && @{$lists[0]} == 3 && @{$lists[1]} == 3 && @{$lists[2]} == 3); | |
52 | print "ok 9\n"; | |
53 | ||
54 | # Now test error return | |
55 | $string = 'foo bar baz"bach blech boop'; | |
56 | ||
57 | @words = shellwords($string); | |
58 | print "not " if (@words); | |
59 | print "ok 10\n"; | |
60 | ||
61 | @words = parse_line('s+', 0, $string); | |
62 | print "not " if (@words); | |
63 | print "ok 11\n"; | |
64 | ||
65 | @words = quotewords('s+', 0, $string); | |
66 | print "not " if (@words); | |
67 | print "ok 12\n"; | |
68 | ||
69 | @words = nested_quotewords('s+', 0, $string); | |
70 | print "not " if (@words); | |
71 | print "ok 13\n"; | |
72 | ||
73 | # Now test empty fields | |
74 | $result = join('|', parse_line(':', 0, 'foo::0:"":::')); | |
75 | print "not " unless ($result eq 'foo||0||||'); | |
76 | print "ok 14\n"; | |
77 | ||
78 | # Test for 0 in quotes without $keep | |
79 | $result = join('|', parse_line(':', 0, ':"0":')); | |
80 | print "not " unless ($result eq '|0|'); | |
81 | print "ok 15\n"; |