# Copyright (c) 2005 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: CSV.bunit,v 1.5 2011/10/13 16:57:34 moeller Exp $ [ [] => [ { method => 'colrm', compute_params => sub { my($case, $params) = @_; my($expect) = $case->get('expect'); $case->expect([\$expect->[0]]); # First parameter is -input value $case->get('object')->put(input => \$params->[0]); shift(@$params); return $params; }, } => [ ["a,b,c\n", 0, 1] => ["b,c\n"], ["a,b,c\n", 1, 2] => ["a\n"], ["a,b,c,d\nw,x,y,z\n", 2] => ["a,b\nw,x\n"], ], to_csv_text => [ [[]] => => [\("\n")], [['']] => => [\("\n")], [[undef]] => => [\("\n")], [[0]] => => [\("0\n")], [[1, 2, 3]] => [\("1,2,3\n")], [['ab"c', ' blah', 'blah ', "foo\n"]] => [\(qq{"ab""c"," blah","blah ","foo\n"\n})], [[ [1, undef, 2], [undef, undef, "\n\n\n",3,4], [], ['the,end'], ]] => [ \(qq{1,,2\n,,"\n\n\n",3,4\n\n"the,end"\n}), ], [["some\ntext"]] => [\(qq{"some\ntext"\n})], [["some\r\ntext"]] => [\(qq{"some\r\ntext"\n})], [["some\rtext"]] => [\(qq{"some\rtext"\n})], ], parse_records => [ [\(my $x = <<'EOF')] a,b,c 1,2,3 4,5,6,7 8,9 EOF => [[ { a => 1, b => 2, c => 3, }, { a => 4, b => 5, c => 6, }, { a => 8, b => 9, c => undef, }, ]], ["a,b,c\n1,2,3"] => [[ { a => 1, b => 2, c => 3, }, ]], ["a,b,c\n1,2,3", 1] => [[ { _line => 2, a => 1, b => 2, c => 3, }, ]], ], { method => 'parse', check_return => sub { my(undef, undef, $expect) = @_; return [$expect]; }, } => [ '' => [], ['', 1] => [], ' ' => [], "\n \r \n" => [], ',' => [['','']], [",,\n", 1] => [[1, '','','']], " \n \r\n \n a \n \n \r\n\n \n" => [[' a ']], [" \n \r\n \n a \n \n \r\n\n \n", 1] => [[4, ' a ']], 'a' => [['a']], [\(my $x2 = 'a')] => [['a']], 'a,b,c' => [[qw(a b c)]], "a,b,c\n" => [[qw(a b c)]], 'a,b,c,' => [[qw(a b c), '']], [qq{1,,2\n,,"\r\n\n\r",3,4\n\n"the,end"\n}] => [ [1, '', 2], ['', '', "\n\n\n",3,4], [''], ['the,end'], ], [qq{1,,2\n,,"\r\n\n\r",3,4\n\n"the,end"\n}, 1] => [ [1, 1, '', 2], [2, '', '', "\n\n\n",3,4], [6, ''], [7, 'the,end'], ], '1""2,3' => DIE(), '"abc"2,3' => DIE(), '"abc2,3' => DIE(), ], ], ];