/
03-quotes.t
43 lines (32 loc) · 1.27 KB
/
03-quotes.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use v6;
use Test;
use Text::CSV;
sub ok_becomes($input, $output, $description = '') {
is_deeply Text::CSV.parse($input), $output, $description;
}
ok_becomes q[[[foo,bar,baz
'foo','bar','baz'
'foo','bar' , 'baz']]],
[ [<foo bar baz>],
["'foo'", "'bar'", "'baz'"],
["'foo'", "'bar' ", " 'baz'"] ],
'single quotes carry no special significance';
ok_becomes q[[[foo,bar,baz
"foo","bar","baz"
"foo","bar" , "baz"]]], [ [<foo bar baz>] xx 3 ], 'double quotes';
lives_ok { Text::CSV.parse(q[[[foo,ba'r,ba'z]]]) },
'mid-string single quotes legal';
dies_ok { Text::CSV.parse(q[[[foo,ba"r,ba"z]]]) },
'mid-string double quotes illegal';
is +Text::CSV.parse(q[[[foo,'bar,baz']]])[0], 3, 'cannot single-quote commas';
is +Text::CSV.parse(q[[[foo,"bar,baz"]]])[0], 2, 'can double-quote commas';
dies_ok { Text::CSV.parse(q[[["foo"oo"]]]) },
'non-duplicated double quotes in double-quoted strings illegal';
lives_ok { Text::CSV.parse(q[[["foo""oo"]]]) },
'duplicated double quotes in double-quoted strings legal';
ok_becomes q[[[foo,"bar","ba""z"]]], [ [<foo bar ba"z>] ], 'quote escaping';
ok_becomes q[[[foo,"ba
r","baz"]]], [ ['foo', 'ba
r', 'baz'] ], 'newlines are allowed inside quotes';
done;
# vim:ft=perl6