Skip to content
Newer
Older
100644 36 lines (24 sloc) 1.09 KB
1a672bb @masak introduced :strict, checking columns
masak authored Aug 21, 2009
1 use v6;
2 use Test;
3
4 use Text::CSV;
5
6 my $input = q[[[one,line,four,words
7 five,words,in,one,line
8 only,three,words]]];
9
ebbec80 @masak s:g/read/parse/ for the Text::CSV methods
masak authored Aug 22, 2009
10 lives_ok { Text::CSV.parse($input) },
1a672bb @masak introduced :strict, checking columns
masak authored Aug 21, 2009
11 'varying numbers of fields parse OK';
12
ebbec80 @masak s:g/read/parse/ for the Text::CSV methods
masak authored Aug 22, 2009
13 dies_ok { Text::CSV.parse($input, :strict) },
1a672bb @masak introduced :strict, checking columns
masak authored Aug 21, 2009
14 'when strict more is on, varying numbers of fields cause an error';
15
ebbec80 @masak s:g/read/parse/ for the Text::CSV methods
masak authored Aug 22, 2009
16 dies_ok { Text::CSV.parse($input, :output<hashes>) },
231ab86 @masak made hash output w/ :!strict make sense
masak authored Aug 22, 2009
17 ':output<hashes> turns on :strict by default';
18
ebbec80 @masak s:g/read/parse/ for the Text::CSV methods
masak authored Aug 22, 2009
19 dies_ok { Text::CSV.parse($input, :output(Any)) },
231ab86 @masak made hash output w/ :!strict make sense
masak authored Aug 21, 2009
20 ':output(Any) turns on :strict by default';
21
ebbec80 @masak s:g/read/parse/ for the Text::CSV methods
masak authored Aug 22, 2009
22 lives_ok { Text::CSV.parse($input, :output<hashes>, :!strict) },
231ab86 @masak made hash output w/ :!strict make sense
masak authored Aug 21, 2009
23 'default :strict can be turned back off for :output<hashes>';
24
ebbec80 @masak s:g/read/parse/ for the Text::CSV methods
masak authored Aug 22, 2009
25 lives_ok { Text::CSV.parse($input, :output(Any), :!strict) },
231ab86 @masak made hash output w/ :!strict make sense
masak authored Aug 21, 2009
26 'default :strict can be turned back off for :output(Any)';
27
ebbec80 @masak s:g/read/parse/ for the Text::CSV methods
masak authored Aug 22, 2009
28 is_deeply Text::CSV.parse($input, :output<hashes>, :!strict),
231ab86 @masak made hash output w/ :!strict make sense
masak authored Aug 21, 2009
29 [ { one => "five", line => "words", four => "in", words => "one" },
30 { one => "only", line => "three", four => "words" } ],
31 'the hashes output under :!strict makes only the necessary pairs';
32
ecd767b @tadzik done_testing() is now done()
authored Apr 14, 2012
33 done;
1a672bb @masak introduced :strict, checking columns
masak authored Aug 21, 2009
34
35 # vim:ft=perl6
Something went wrong with that request. Please try again.