1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Exception;
use Data::Dumper;
my $pkg;
my $pkg2;
BEGIN {
$pkg = 'Catmandu::Fix::mapping';
use_ok $pkg;
}
is_deeply $pkg->new('t/field_mapping.csv', sep_char => ';')
->fix({title => "Computational Biology"}),
{Title => "Computational Biology"}, "map simple field";
is_deeply $pkg->new('t/field_mapping.csv', sep_char => ';')->fix(
{
title => "Computational Biology",
author => "C. Ungewitter",
id => "3279423874"
}
),
{
Title => "Computational Biology",
Author => "C. Ungewitter",
Identifier => "3279423874"
},
"map several fields";
is_deeply $pkg->new('t/field_mapping.csv', sep_char => ';')
->fix({publisher => "Springer"}),
{Publisher => [{nested => "Springer"}]}, "map nested field";
is_deeply $pkg->new('t/field_mapping.csv', sep_char => ';', 'keep', 1)
->fix({publisher => "Springer"}),
{Publisher => [{nested => "Springer"}], publisher => "Springer"},
"map nested field with keep option";
is_deeply $pkg->new('t/field_mapping.csv', 'keep', 1, sep_char => ';')
->fix({publisher => "Springer"}),
{Publisher => [{nested => "Springer"}], publisher => "Springer"},
"map nested field with keep option";
done_testing;
|