Revision ccb40ac4
Von Bernd Bleßmann vor fast 11 Jahren hinzugefügt
t/helper/csv.t | ||
---|---|---|
1 |
use Test::More tests => 71;
|
|
1 |
use Test::More tests => 75;
|
|
2 | 2 |
|
3 | 3 |
use lib 't'; |
4 | 4 |
use utf8; |
... | ... | |
551 | 551 |
|
552 | 552 |
##### |
553 | 553 |
|
554 |
$csv = SL::Helper::Csv->new( |
|
555 |
file => \<<EOL, |
|
556 |
description;longdescription;datatype |
|
557 |
name;customernumber;datatype |
|
558 |
Kaffee;"lecker Kaffee";P |
|
559 |
Meier;1;C |
|
560 |
Bier;"kühles Bier";P |
|
561 |
Mueller;2;C |
|
562 |
EOL |
|
563 |
# " # make emacs happy |
|
564 |
profile => [ |
|
565 |
{class => 'SL::DB::Part', row_ident => 'P'}, |
|
566 |
{class => 'SL::DB::Customer', row_ident => 'C'}, |
|
567 |
], |
|
568 |
ignore_unknown_columns => 1, |
|
569 |
); |
|
570 |
$csv->parse; |
|
571 |
is $csv->_multiplex_datatype_position, 2, 'multiplex check detects datatype field position right'; |
|
572 |
|
|
573 |
is_deeply $csv->get_data, [ { datatype => 'P', description => 'Kaffee', longdescription => 'lecker Kaffee' }, |
|
574 |
{ datatype => 'C', name => 'Meier', customernumber => 1}, |
|
575 |
{ datatype => 'P', description => 'Bier', longdescription => 'kühles Bier' }, |
|
576 |
{ datatype => 'C', name => 'Mueller', customernumber => 2} |
|
577 |
], |
|
578 |
'multiplex: datatype not at first position works'; |
|
579 |
|
|
580 |
##### |
|
581 |
|
|
582 |
$csv = SL::Helper::Csv->new( |
|
583 |
file => \<<EOL, |
|
584 |
datatype;description;longdescription |
|
585 |
name;datatype;customernumber |
|
586 |
P;Kaffee;"lecker Kaffee" |
|
587 |
Meier;C;1 |
|
588 |
P;Bier;"kühles Bier" |
|
589 |
Mueller;C;2 |
|
590 |
EOL |
|
591 |
# " # make emacs happy |
|
592 |
profile => [ |
|
593 |
{class => 'SL::DB::Part', row_ident => 'P'}, |
|
594 |
{class => 'SL::DB::Customer', row_ident => 'C'}, |
|
595 |
], |
|
596 |
ignore_unknown_columns => 1, |
|
597 |
); |
|
598 |
ok !$csv->parse, 'multiplex check detects incosistent datatype field position'; |
|
599 |
is_deeply( ($csv->errors)[0], [ 0, 'datatype field must be at the same position for all datatypes for multiplexed data', 0, 0 ], 'multiplex data with inconsistent datatype field posiotion throws error'); |
|
600 |
|
|
601 |
##### |
|
602 |
|
|
554 | 603 |
$csv = SL::Helper::Csv->new( |
555 | 604 |
file => \"Datatype;Description\nDatatype;Name\nP;Kaffee\nC;Meier", # " # make emacs happy |
556 | 605 |
case_insensitive_header => 1, |
Auch abrufbar als: Unified diff
CSV-Import mit Multiplex-Daten: Die Spalte datatype muss nicht an der ersten Position sein.