Debian Codegraph @

t/Catmandu/Fix/marc_in_json.t

raw
1 #!perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Test::Exception;
7 use Test::Deep;
8 use Catmandu::Importer::MARC;
9 use Catmandu::Fix;
10 use utf8;
11
12 my $pkg;
13
14 BEGIN {
15 $pkg = 'Catmandu::Fix::marc_in_json';
16 use_ok $pkg;
17 }
18
19 require_ok $pkg;
20
21 my $record = {
22 record => [
23 ['LDR', undef, undef, '_', '00000nas-a2200000z--4500'],
24 ['001', undef, undef, undef, 'rec002'],
25 ['008', undef, undef, '_' , '150519s----------------------000---eng-d'] ,
26 ['100', '1', '1',
27 '_', '' ,
28 'a', 'Slayer'
29 ],
30 ['245', ' ', ' ',
31 '_', '' ,
32 'a', 'Reign in Blood' ,
33 ],
34 ['999', ' ', ' ',
35 '_', '' ,
36 'x', 'test' ,
37 'x', 'test2' ,
38 'x', 'test3' ,
39 ]
40 ]
41 };
42
43 my $fixer = Catmandu::Fix->new(fixes => [q|marc_in_json()|]);
44 my $record2 = $fixer->fix($record);
45
46 is $record2->{leader}, qq|00000nas-a2200000z--4500|;
47 is $record2->{fields}->[0]->{'001'}, qq|rec002|;
48 is $record2->{fields}->[1]->{'008'}, qq|150519s----------------------000---eng-d|;
49 is $record2->{fields}->[2]->{'100'}->{'ind1'} , 1;
50 is $record2->{fields}->[2]->{'100'}->{'ind2'} , 1;
51 is $record2->{fields}->[2]->{'100'}->{'subfields'}->[0]->{a} , 'Slayer';
52 is $record2->{fields}->[3]->{'245'}->{'subfields'}->[0]->{a} , 'Reign in Blood';
53 is $record2->{fields}->[4]->{'999'}->{'subfields'}->[0]->{x} , 'test';
54 is $record2->{fields}->[4]->{'999'}->{'subfields'}->[1]->{x} , 'test2';
55 is $record2->{fields}->[4]->{'999'}->{'subfields'}->[2]->{x} , 'test3';
56
57 my $fixer2 = Catmandu::Fix->new(fixes => [q|marc_in_json(-reverse => 1)|]);
58 my $record3 = $fixer2->fix($record2);
59
60 cmp_deeply($record,$record3);
61
62 done_testing;