1 |
|
use Test::More tests => 86;
|
|
1 |
use Test::More tests => 91;
|
2 |
2 |
|
3 |
3 |
use lib 't';
|
4 |
4 |
use utf8;
|
... | ... | |
382 |
382 |
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'without profile and class works';
|
383 |
383 |
|
384 |
384 |
#####
|
|
385 |
|
|
386 |
$csv = SL::Helper::Csv->new(
|
|
387 |
file => \<<EOL,
|
|
388 |
description;partnumber
|
|
389 |
Kaffee;1
|
|
390 |
|
|
391 |
;
|
|
392 |
;
|
|
393 |
Tee;3
|
|
394 |
EOL
|
|
395 |
# Note: The second last line is not empty. The description is a space character.
|
|
396 |
);
|
|
397 |
ok $csv->parse;
|
|
398 |
is_deeply $csv->get_data, [ {partnumber => 1, description => 'Kaffee'}, {partnumber => '', description => ' '}, {partnumber => 3, description => 'Tee'} ], 'ignoring empty lines works (header in csv file)';
|
|
399 |
|
|
400 |
#####
|
|
401 |
|
|
402 |
$csv = SL::Helper::Csv->new(
|
|
403 |
file => \<<EOL,
|
|
404 |
Kaffee;1
|
|
405 |
|
|
406 |
;
|
|
407 |
;
|
|
408 |
Tee;3
|
|
409 |
EOL
|
|
410 |
# Note: The second last line is not empty. The description is a space character.
|
|
411 |
header => ['description', 'partnumber'],
|
|
412 |
);
|
|
413 |
ok $csv->parse;
|
|
414 |
is_deeply $csv->get_data, [ {partnumber => 1, description => 'Kaffee'}, {partnumber => '', description => ' '}, {partnumber => 3, description => 'Tee'} ], 'ignoring empty lines works';
|
|
415 |
|
|
416 |
#####
|
|
417 |
|
385 |
418 |
$csv = SL::Helper::Csv->new(
|
386 |
419 |
file => \"Kaffee;1,50\nSchoke;0,89\n",
|
387 |
420 |
header => [
|
... | ... | |
726 |
759 |
|
727 |
760 |
#####
|
728 |
761 |
|
|
762 |
$csv = SL::Helper::Csv->new(
|
|
763 |
file => \<<EOL,
|
|
764 |
datatype;customernumber;name
|
|
765 |
datatype;description;partnumber
|
|
766 |
C;1000;Meier
|
|
767 |
P;Kaffee;1
|
|
768 |
|
|
769 |
;;
|
|
770 |
C
|
|
771 |
P; ;
|
|
772 |
C;2000;Meister
|
|
773 |
P;Tee;3
|
|
774 |
EOL
|
|
775 |
ignore_unknown_columns => 1,
|
|
776 |
profile => [ { class => 'SL::DB::Customer', row_ident => 'C' },
|
|
777 |
{ class => 'SL::DB::Part', row_ident => 'P' },
|
|
778 |
],
|
|
779 |
);
|
|
780 |
$csv->parse;
|
|
781 |
is_deeply $csv->get_data, [
|
|
782 |
{datatype => 'C', customernumber => 1000, name => 'Meier'},
|
|
783 |
{datatype => 'P', partnumber => 1, description => 'Kaffee'},
|
|
784 |
{datatype => 'C', customernumber => undef, name => undef},
|
|
785 |
{datatype => 'P', partnumber => '', description => ' '},
|
|
786 |
{datatype => 'C', customernumber => 2000, name => 'Meister'},
|
|
787 |
{datatype => 'P', partnumber => '3', description => 'Tee'},
|
|
788 |
], 'ignoring empty lines works (multiplex data)';
|
|
789 |
|
|
790 |
#####
|
|
791 |
|
729 |
792 |
# Mappings
|
730 |
793 |
# simple case
|
731 |
794 |
$csv = SL::Helper::Csv->new(
|
CSV-Helfer: Leere Zeilen ignorieren.
Als leere Zeilen hier gelten auch Zeilen, die nur das Trennzeichen enthalten.
Mit leeren Zeilen gab es immer wieder Probleme, teils mit schwer zu
interpretierenden Fehlermeldungen, teils mit nicht gewünschtem Verhalten, z.B.
beim Warenimport das Anlegen neuer Artikel für jede leere Zeile.