| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use Test::Exception; |
| 7 |
use Catmandu::Importer::MARC; |
| 8 |
use Catmandu::Fix; |
| 9 |
use utf8; |
| 10 |
|
| 11 |
my $pkg; |
| 12 |
|
| 13 |
BEGIN { |
| 14 |
$pkg = 'Catmandu::Fix::marc_spec'; |
| 15 |
use_ok $pkg; |
| 16 |
} |
| 17 |
|
| 18 |
require_ok $pkg; |
| 19 |
|
| 20 |
my $fixer = Catmandu::Fix->new(fixes => ['t/marc_spec.fix']); |
| 21 |
my $importer = Catmandu::Importer::MARC->new( file => 't/camel9.mrc', type => "ISO" ); |
| 22 |
my $records = $fixer->fix($importer)->to_array; |
| 23 |
|
| 24 |
is $records->[0]->{my}{id}, 'fol05882032 ', q|fix: marc_spec('001', my.id);|; |
| 25 |
ok !defined $records->[0]->{my}{no}{field}, q|fix: marc_spec('000', my.no.field);|; |
| 26 |
|
| 27 |
#field 666 does not exist in camel.usmarc |
| 28 |
#he '$append' fix creates $my->{'references'} hash key with empty array ref as value |
| 29 |
ok !$records->[0]->{'my'}{'references'}, q|fix: marc_spec('666', my.references.$append);|; |
| 30 |
|
| 31 |
is_deeply |
| 32 |
$records->[0]->{'my'}{'references2'}, |
| 33 |
[ |
| 34 |
'first', |
| 35 |
'IMchF' |
| 36 |
], |
| 37 |
q|fix: add_field(my.references2.$first, 'first'); marc_spec('003', my.references2.$append);|; |
| 38 |
|
| 39 |
is $records->[0]->{my}{title}{all}, 'Cross-platform Perl /Eric F. Johnson.', q|fix: marc_spec('245', my.title.all);|; |
| 40 |
|
| 41 |
is $records->[0]->{my}{title}{default}, 'the title', q|fix: marc_spec('245', my.title.default, value:'the title');|; |
| 42 |
|
| 43 |
is $records->[0]->{my}{subjects}{all}, 'Perl (Computer program language)Web servers.Cross-platform software development.', q|fix: marc_spec('650', my.subjects.all);|; |
| 44 |
|
| 45 |
is $records->[0]->{my}{subjects}{joined}, 'Perl (Computer program language)###Web servers.###Cross-platform software development.', q|fix: marc_spec('650', my.subjects.joined, join:'###');|; |
| 46 |
|
| 47 |
is_deeply |
| 48 |
$records->[0]->{my}{append}{subjects}, |
| 49 |
[ |
| 50 |
'Perl (Computer program language)', |
| 51 |
'Web servers.', |
| 52 |
'Cross-platform software development.' |
| 53 |
], |
| 54 |
q|fix: marc_spec('650', my.append.subjects.$append);|; |
| 55 |
|
| 56 |
is_deeply |
| 57 |
$records->[0]->{my}{split}{subjects}, |
| 58 |
[ |
| 59 |
'Perl (Computer program language)', |
| 60 |
'Web servers.', |
| 61 |
'Cross-platform software development.' |
| 62 |
], |
| 63 |
q|fix: marc_spec('650', my.split.subjects, split:1);|; |
| 64 |
|
| 65 |
is_deeply |
| 66 |
$records->[0]->{my}{append}{split}{subjects}, |
| 67 |
[ |
| 68 |
[ |
| 69 |
"Perl (Computer program language)", |
| 70 |
"Web servers.", |
| 71 |
"Cross-platform software development." |
| 72 |
] |
| 73 |
], |
| 74 |
q|fix: marc_spec('650', my.append.split.subjects.$append, split:1);|; |
| 75 |
|
| 76 |
is_deeply |
| 77 |
$records->[0]->{my}{fields}{indicators10}, |
| 78 |
['Cross-platform Perl /Eric F. Johnson.'], |
| 79 |
q|fix: marc_spec('...{^1=\1}{^2=\0}', my.fields.indicators10.$append);|; |
| 80 |
|
| 81 |
is scalar @{$records->[0]->{my}{fields}{indicators_0}}, 9, q|fix: marc_spec('...{^2=\0}', my.fields.indicators_0, split:1);|; |
| 82 |
|
| 83 |
is $records->[0]->{my}{ldr}{all}, '00696nam 22002538a 4500', q|fix: marc_spec('LDR', my.ldr.all);|; |
| 84 |
|
| 85 |
is $records->[0]->{my}{firstcharpos}{ldr}, '0069', q|fix: marc_spec('LDR', my.firstcharpos.ldr);|; |
| 86 |
|
| 87 |
is $records->[0]->{my}{lastcharpos}{ldr}, '4500', q|fix: marc_spec('LDR/#-3', my.lastcharpos.ldr);|; |
| 88 |
|
| 89 |
is $records->[0]->{my}{title}{proper}, 'Cross-platform Perl /', q|fix: marc_spec('245$a', my.title.proper);|; |
| 90 |
|
| 91 |
is $records->[0]->{my}{title}{indicator}{proper}, 'Cross-platform Perl /', q|fix: marc_spec('245$a{^1=\1}{^2=\0}', my.title.indicator.proper);|; |
| 92 |
|
| 93 |
is $records->[0]->{my}{title}{charpos}, 'Cr', q|fix: marc_spec('245$a/0-1', my.title.charpos);|; |
| 94 |
|
| 95 |
is $records->[0]->{my}{second}{subject}, 'Web servers.', q|fix: marc_spec('650[1]', my.second.subjects);|; |
| 96 |
is $records->[0]->{my}{last}{subject}, 'Cross-platform software development.', q|fix: marc_spec('650[#]', my.last.subjects);|; |
| 97 |
|
| 98 |
is_deeply |
| 99 |
$records->[0]->{my}{two}{split}{subjects}, |
| 100 |
['Perl (Computer program language)', 'Web servers.'], |
| 101 |
q|fix: marc_spec('650[0-1]', my.two.split.subjects, split:1);|; |
| 102 |
|
| 103 |
is $records->[0]->{my}{two}{join}{subjects}, 'Web servers.###Cross-platform software development.', q|fix: marc_spec('650[#-1]', my.two.join.subjects, join:'###');|; |
| 104 |
|
| 105 |
is $records->[0]->{my}{isbn}{number}, '0764547291 (alk. paper)0491001304test0491001304', q|fix: marc_spec('020$a[0]', my.isbn.number);|; |
| 106 |
is $records->[0]->{my}{isbn}{numbers}, '0764547291 (alk. paper)0491001304', q|fix: marc_spec('020$a[0]', my.isbn.numbers);|; |
| 107 |
ok !defined $records->[0]->{my}{isbn}{qual}{none}, q|fix: marc_spec('020[0]$q[0]', my.isbn.qual.none);|; |
| 108 |
is $records->[0]->{my}{isbn}{qual}{first}, 'black leather', q|fix: marc_spec('020$q[0]', my.isbn.qual.first);|; |
| 109 |
is $records->[0]->{my}{isbn}{qual}{second}, 'blue pigskin', q|fix: marc_spec('020$q[1]', my.isbn.qual.second);|; |
| 110 |
is $records->[0]->{my}{isbn}{qual}{last}, 'easel binding', q|fix: marc_spec('020$q[#]', my.isbn.qual.last);|; |
| 111 |
is_deeply |
| 112 |
$records->[0]->{my}{isbns}{all}, |
| 113 |
[ |
| 114 |
"0764547291 (alk. paper)", |
| 115 |
"0491001304", |
| 116 |
"test0491001304", |
| 117 |
"black leather", |
| 118 |
"blue pigskin", |
| 119 |
"easel binding" |
| 120 |
], |
| 121 |
q|fix: marc_spec('020$q$a', my.isbns.all, split:1);|; |
| 122 |
is_deeply |
| 123 |
$records->[0]->{my}{isbns}{pluck}{all}, |
| 124 |
[ |
| 125 |
"0764547291 (alk. paper)", |
| 126 |
"black leather", |
| 127 |
"blue pigskin", |
| 128 |
"easel binding", |
| 129 |
"0491001304", |
| 130 |
"test0491001304" |
| 131 |
], |
| 132 |
q|fix: marc_spec('020$q$a', my.isbns.all, split:1, pluck:1);|; |
| 133 |
is_deeply |
| 134 |
$records->[0]->{my}{isbn}{qual}{other}, |
| 135 |
[ |
| 136 |
"test0491001304", |
| 137 |
"easel binding" |
| 138 |
], |
| 139 |
q|fix: marc_spec('020$q[#]$a[1]', my.isbn.qual.other, split:1);|; |
| 140 |
is_deeply |
| 141 |
$records->[0]->{my}{isbn}{qual}{range}, |
| 142 |
[ |
| 143 |
"0764547291 (alk. paper)", |
| 144 |
"0491001304", |
| 145 |
"test0491001304", |
| 146 |
"blue pigskin", |
| 147 |
"easel binding" |
| 148 |
], |
| 149 |
q|fix: marc_spec('020$q[#-1]$a[0-1]', my.isbn.qual.range, split:1);|; |
| 150 |
is_deeply |
| 151 |
$records->[0]->{my}{isbn}{qual}{substring}{other}, |
| 152 |
[ |
| 153 |
"4", |
| 154 |
"easel" |
| 155 |
], |
| 156 |
q|fix: marc_spec('020$q[#]/0-4$a[1]/#-0', my.isbn.qual.substring.other, split:1);|; |
| 157 |
|
| 158 |
is $records->[0]->{my}{level3}{inverted}, '2000.', q|fix: marc_spec('260[#]$b$a', my.level3.inverted, invert:1);|; |
| 159 |
is $records->[0]->{my}{level2}{inverted}, 'black leatherblue pigskin', q|fix: marc_spec('020$a$q[#]', my.level2.inverted, invert:1);|; |
| 160 |
is $records->[0]->{my}{level1}{inverted}, 'ebinding', q|fix: marc_spec('020[#]$a$q[#]/1-5', my.level1.inverted, invert:1);|; |
| 161 |
is $records->[0]->{my}{multi}{level1}{inverted}, 'bleatherbigskinebinding', q|fix: marc_spec('020[#]$a$q[0]/1-5$q[1]/1-5$q[2]/1-5', my.multi.level1.inverted, invert:1);|; |
| 162 |
|
| 163 |
is $records->[0]->{my}{nullvalue} , '0' , q|fix: marc_spec('008/0', my.nullvalue);|; |
| 164 |
|
| 165 |
done_testing; |