| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use Test::Exception; |
| 7 |
use Catmandu; |
| 8 |
|
| 9 |
my $pkg; |
| 10 |
|
| 11 |
BEGIN { |
| 12 |
$pkg = 'Catmandu::Fix::marc_copy'; |
| 13 |
use_ok $pkg; |
| 14 |
} |
| 15 |
|
| 16 |
require_ok $pkg; |
| 17 |
|
| 18 |
my $mrc = <<'MRC'; |
| 19 |
<?xml version="1.0" encoding="UTF-8"?> |
| 20 |
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim"> |
| 21 |
<marc:record> |
| 22 |
<marc:controlfield tag="001"> 92005291 </marc:controlfield> |
| 23 |
<marc:datafield ind1="1" ind2="0" tag="245"> |
| 24 |
<marc:subfield code="a">Title / </marc:subfield> |
| 25 |
<marc:subfield code="c">Name</marc:subfield> |
| 26 |
</marc:datafield> |
| 27 |
<marc:datafield ind1=" " ind2=" " tag="999"> |
| 28 |
<marc:subfield code="a">X</marc:subfield> |
| 29 |
<marc:subfield code="a">Y</marc:subfield> |
| 30 |
</marc:datafield> |
| 31 |
<marc:datafield ind1=" " ind2=" " tag="999"> |
| 32 |
<marc:subfield code="a">Z</marc:subfield> |
| 33 |
</marc:datafield> |
| 34 |
</marc:record> |
| 35 |
</marc:collection> |
| 36 |
MRC |
| 37 |
|
| 38 |
note 'marc_copy(001,cntrl)'; |
| 39 |
{ |
| 40 |
my $importer = Catmandu->importer( |
| 41 |
'MARC', |
| 42 |
file => \$mrc, |
| 43 |
type => 'XML', |
| 44 |
fix => 'marc_copy(001,cntrl); retain_field(cntrl)' |
| 45 |
); |
| 46 |
my $record = $importer->first; |
| 47 |
is_deeply $record->{cntrl}, |
| 48 |
[ |
| 49 |
{ |
| 50 |
tag => '001', |
| 51 |
ind1 => ' ', |
| 52 |
ind2 => ' ', |
| 53 |
content => " 92005291 " |
| 54 |
} |
| 55 |
], 'marc_copy(001,cntrl)'; |
| 56 |
} |
| 57 |
|
| 58 |
note 'marc_copy(245,title)'; |
| 59 |
{ |
| 60 |
my $importer = Catmandu->importer( |
| 61 |
'MARC', |
| 62 |
file => \$mrc, |
| 63 |
type => 'XML', |
| 64 |
fix => 'marc_copy(245,title); retain_field(title)' |
| 65 |
); |
| 66 |
my $record = $importer->first; |
| 67 |
is_deeply $record->{title}, |
| 68 |
[ |
| 69 |
{ |
| 70 |
tag => '245', |
| 71 |
ind1 => '1', |
| 72 |
ind2 => '0', |
| 73 |
subfields => [ |
| 74 |
{ a => 'Title / '}, |
| 75 |
{ c => 'Name' }, |
| 76 |
] |
| 77 |
} |
| 78 |
], 'marc_map(245,title)'; |
| 79 |
} |
| 80 |
|
| 81 |
note 'marc_copy(245a,title)'; |
| 82 |
{ |
| 83 |
my $importer = Catmandu->importer( |
| 84 |
'MARC', |
| 85 |
file => \$mrc, |
| 86 |
type => 'XML', |
| 87 |
fix => 'marc_copy(245a,title); retain_field(title)' |
| 88 |
); |
| 89 |
my $record = $importer->first; |
| 90 |
is_deeply $record->{title}, |
| 91 |
[ |
| 92 |
{ |
| 93 |
tag => '245', |
| 94 |
ind1 => '1', |
| 95 |
ind2 => '0', |
| 96 |
subfields => [ |
| 97 |
{ a => 'Title / '}, |
| 98 |
{ c => 'Name' }, |
| 99 |
] |
| 100 |
} |
| 101 |
], 'marc_map(245a,title)'; |
| 102 |
} |
| 103 |
|
| 104 |
note 'marc_copy(245x,title)'; |
| 105 |
{ |
| 106 |
my $importer = Catmandu->importer( |
| 107 |
'MARC', |
| 108 |
file => \$mrc, |
| 109 |
type => 'XML', |
| 110 |
fix => 'marc_copy(245x,title); retain_field(title)' |
| 111 |
); |
| 112 |
my $record = $importer->first; |
| 113 |
is_deeply $record->{title}, |
| 114 |
[ |
| 115 |
], 'marc_map(245x,title)'; |
| 116 |
} |
| 117 |
|
| 118 |
note 'marc_copy(245a,title,equals:"Title / ")'; |
| 119 |
{ |
| 120 |
my $importer = Catmandu->importer( |
| 121 |
'MARC', |
| 122 |
file => \$mrc, |
| 123 |
type => 'XML', |
| 124 |
fix => 'marc_copy(245a,title,equals:"Title / "); retain_field(title)' |
| 125 |
); |
| 126 |
my $record = $importer->first; |
| 127 |
is_deeply $record->{title}, |
| 128 |
[ |
| 129 |
{ |
| 130 |
tag => '245', |
| 131 |
ind1 => '1', |
| 132 |
ind2 => '0', |
| 133 |
subfields => [ |
| 134 |
{ a => 'Title / '}, |
| 135 |
{ c => 'Name' }, |
| 136 |
] |
| 137 |
} |
| 138 |
], 'marc_map(245a,title,equals:"Title / ")'; |
| 139 |
} |
| 140 |
|
| 141 |
note 'marc_copy(999,local)'; |
| 142 |
{ |
| 143 |
my $importer = Catmandu->importer( |
| 144 |
'MARC', |
| 145 |
file => \$mrc, |
| 146 |
type => 'XML', |
| 147 |
fix => 'marc_copy(999,local); retain_field(local)' |
| 148 |
); |
| 149 |
my $record = $importer->first; |
| 150 |
is_deeply $record->{local}, |
| 151 |
[ |
| 152 |
{ |
| 153 |
tag => '999', |
| 154 |
ind1 => ' ', |
| 155 |
ind2 => ' ', |
| 156 |
subfields => [ |
| 157 |
{ a => 'X'}, |
| 158 |
{ a => 'Y'} |
| 159 |
] |
| 160 |
}, |
| 161 |
{ |
| 162 |
tag => '999', |
| 163 |
ind1 => ' ', |
| 164 |
ind2 => ' ', |
| 165 |
subfields => [ |
| 166 |
{ a => 'Z'} |
| 167 |
] |
| 168 |
} |
| 169 |
], 'marc_copy(999,local)'; |
| 170 |
} |
| 171 |
|
| 172 |
note 'marc_copy(...,all)'; |
| 173 |
{ |
| 174 |
my $importer = Catmandu->importer( |
| 175 |
'MARC', |
| 176 |
file => \$mrc, |
| 177 |
type => 'XML', |
| 178 |
fix => 'marc_copy(...,all); retain_field(all)' |
| 179 |
); |
| 180 |
my $record = $importer->first; |
| 181 |
is_deeply $record->{all}, |
| 182 |
[ |
| 183 |
{ |
| 184 |
tag => 'LDR', |
| 185 |
ind1 => ' ', |
| 186 |
ind2 => ' ', |
| 187 |
content => " " |
| 188 |
}, |
| 189 |
{ |
| 190 |
tag => '001', |
| 191 |
ind1 => ' ', |
| 192 |
ind2 => ' ', |
| 193 |
content => " 92005291 " |
| 194 |
}, |
| 195 |
{ |
| 196 |
tag => '245', |
| 197 |
ind1 => '1', |
| 198 |
ind2 => '0', |
| 199 |
subfields => [ |
| 200 |
{ a => 'Title / '}, |
| 201 |
{ c => 'Name' }, |
| 202 |
] |
| 203 |
}, |
| 204 |
{ |
| 205 |
tag => '999', |
| 206 |
ind1 => ' ', |
| 207 |
ind2 => ' ', |
| 208 |
subfields => [ |
| 209 |
{ a => 'X'}, |
| 210 |
{ a => 'Y'} |
| 211 |
] |
| 212 |
}, |
| 213 |
{ |
| 214 |
tag => '999', |
| 215 |
ind1 => ' ', |
| 216 |
ind2 => ' ', |
| 217 |
subfields => [ |
| 218 |
{ a => 'Z'} |
| 219 |
] |
| 220 |
} |
| 221 |
], 'marc_copy(...,all)'; |
| 222 |
} |
| 223 |
|
| 224 |
done_testing; |