Revision de4b1e97
Von Bernd Bleßmann vor fast 11 Jahren hinzugefügt
t/helper/csv.t | ||
---|---|---|
1 |
use Test::More tests => 64;
|
|
1 |
use Test::More tests => 71;
|
|
2 | 2 |
|
3 | 3 |
use lib 't'; |
4 | 4 |
use utf8; |
... | ... | |
549 | 549 |
); |
550 | 550 |
ok !$csv->_check_multiplexed, 'multiplex check detects empty header'; |
551 | 551 |
|
552 |
##### |
|
553 |
|
|
554 |
$csv = SL::Helper::Csv->new( |
|
555 |
file => \"Datatype;Description\nDatatype;Name\nP;Kaffee\nC;Meier", # " # make emacs happy |
|
556 |
case_insensitive_header => 1, |
|
557 |
ignore_unknown_columns => 1, |
|
558 |
profile => [ |
|
559 |
{ |
|
560 |
profile => { datatype => 'datatype', description => 'description' }, |
|
561 |
class => 'SL::DB::Part', |
|
562 |
row_ident => 'P' |
|
563 |
}, |
|
564 |
{ |
|
565 |
profile => { datatype => 'datatype', name => 'name' }, |
|
566 |
class => 'SL::DB::Customer', |
|
567 |
row_ident => 'C' |
|
568 |
} |
|
569 |
], |
|
570 |
); |
|
571 |
$csv->parse; |
|
572 |
is_deeply $csv->get_data, [ { datatype => 'P', description => 'Kaffee' }, |
|
573 |
{ datatype => 'C', name => 'Meier'} ], |
|
574 |
'multiplex: case insensitive header from csv works'; |
|
575 |
|
|
576 |
##### |
|
577 |
|
|
578 |
$csv = SL::Helper::Csv->new( |
|
579 |
file => \"P;Kaffee\nC;Meier", # " # make emacs happy |
|
580 |
header => [[ 'Datatype', 'Description' ], [ 'Datatype', 'Name']], |
|
581 |
case_insensitive_header => 1, |
|
582 |
profile => [ |
|
583 |
{ |
|
584 |
profile => { datatype => 'datatype', description => 'description' }, |
|
585 |
class => 'SL::DB::Part', |
|
586 |
row_ident => 'P' |
|
587 |
}, |
|
588 |
{ |
|
589 |
profile => { datatype => 'datatype', name => 'name' }, |
|
590 |
class => 'SL::DB::Customer', |
|
591 |
row_ident => 'C' |
|
592 |
} |
|
593 |
], |
|
594 |
); |
|
595 |
$csv->parse; |
|
596 |
is_deeply $csv->get_data, [ { datatype => 'P', description => 'Kaffee' }, |
|
597 |
{ datatype => 'C', name => 'Meier' } ], |
|
598 |
'multiplex: case insensitive header as param works'; |
|
599 |
|
|
600 |
|
|
601 |
##### |
|
602 |
|
|
603 |
$csv = SL::Helper::Csv->new( |
|
604 |
file => \"P;Kaffee\nC;Meier", # " # make emacs happy |
|
605 |
header => [[ 'Datatype', 'Description' ], [ 'Datatype', 'Name']], |
|
606 |
profile => [ |
|
607 |
{ |
|
608 |
profile => { datatype => 'datatype', description => 'description' }, |
|
609 |
class => 'SL::DB::Part', |
|
610 |
row_ident => 'P' |
|
611 |
}, |
|
612 |
{ |
|
613 |
profile => { datatype => 'datatype', name => 'name' }, |
|
614 |
class => 'SL::DB::Customer', |
|
615 |
row_ident => 'C' |
|
616 |
} |
|
617 |
], |
|
618 |
); |
|
619 |
$csv->parse; |
|
620 |
is_deeply $csv->get_data, undef, 'multiplex: case insensitive header without flag ignores'; |
|
621 |
|
|
622 |
##### |
|
623 |
|
|
624 |
$csv = SL::Helper::Csv->new( |
|
625 |
file => \<<EOL, |
|
626 |
P;Kaffee;lecker |
|
627 |
C;Meier;froh |
|
628 |
EOL |
|
629 |
# " # make emacs happy |
|
630 |
header => [[ 'datatype', 'Afoo', 'Abar' ], [ 'datatype', 'Bfoo', 'Bbar']], |
|
631 |
profile => [{ |
|
632 |
profile => { datatype => '', Afoo => '', Abar => '' }, |
|
633 |
class => 'SL::DB::Part', |
|
634 |
row_ident => 'P' |
|
635 |
}, |
|
636 |
{ |
|
637 |
profile => { datatype => '', Bfoo => '', Bbar => '' }, |
|
638 |
class => 'SL::DB::Customer', |
|
639 |
row_ident => 'C' |
|
640 |
}], |
|
641 |
); |
|
642 |
$csv->parse; |
|
643 |
|
|
644 |
is_deeply $csv->get_data, |
|
645 |
[ { datatype => 'P', Afoo => 'Kaffee', Abar => 'lecker' }, { datatype => 'C', Bfoo => 'Meier', Bbar => 'froh' } ], |
|
646 |
'multiplex: empty path still gets parsed into data'; |
|
647 |
ok $csv->get_objects->[0], 'multiplex: empty path gets ignored in object creation'; |
|
648 |
|
|
649 |
##### |
|
650 |
|
|
651 |
$csv = SL::Helper::Csv->new( |
|
652 |
file => \<<EOL, |
|
653 |
P;Kaffee;lecker |
|
654 |
C;Meier;froh |
|
655 |
EOL |
|
656 |
# " # make emacs happy |
|
657 |
header => [[ 'datatype', 'Afoo', 'Abar' ], [ 'datatype', 'Bfoo', 'Bbar']], |
|
658 |
strict_profile => 1, |
|
659 |
profile => [{ |
|
660 |
profile => { datatype => '', Afoo => '', Abar => '' }, |
|
661 |
class => 'SL::DB::Part', |
|
662 |
row_ident => 'P' |
|
663 |
}, |
|
664 |
{ |
|
665 |
profile => { datatype => '', Bfoo => '', Bbar => '' }, |
|
666 |
class => 'SL::DB::Customer', |
|
667 |
row_ident => 'C' |
|
668 |
}], |
|
669 |
); |
|
670 |
$csv->parse; |
|
671 |
|
|
672 |
is_deeply $csv->get_data, |
|
673 |
[ { datatype => 'P', Afoo => 'Kaffee', Abar => 'lecker' }, { datatype => 'C', Bfoo => 'Meier', Bbar => 'froh' } ], |
|
674 |
'multiplex: empty path still gets parsed into data (strict profile)'; |
|
675 |
ok $csv->get_objects->[0], 'multiplex: empty path gets ignored in object creation (strict profile)'; |
|
676 |
|
|
677 |
##### |
|
678 |
|
|
552 | 679 |
|
553 | 680 |
# vim: ft=perl |
554 | 681 |
# set emacs to perl mode |
Auch abrufbar als: Unified diff
case_insensitive-Flag für Multiplex-Daten anpassen.