Debian Codegraph @

t/Catmandu/Fix/marc_cut.t

raw symbols SCIP
1 #!perl
2
3 use strictscip-perl cpan Catmandu-MARC 1.32 strict/;
4 use warningsscip-perl cpan Catmandu-MARC 1.32 warnings/;
5 use Test::Morescip-perl cpan Catmandu-MARC 1.32 Test/More/;
6 use Test::Exceptionscip-perl cpan Catmandu-MARC 1.32 Test/Exception/;
7 use Catmanduscip-perl cpan Catmandu-MARC 1.32 Catmandu/;
8
9 my $pkg;
10
11 BEGIN {
12 $pkg = 'Catmandu::Fix::marc_cut';
13 use_okscip-perl cpan Catmandu-MARC 1.32 main/use_ok(). $pkg;
14 }
15
16 require_okscip-perl cpan Catmandu-MARC 1.32 main/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 notescip-perl cpan Catmandu-MARC 1.32 main/note(). 'marc_cut(001,cntrl)';
39 {
40 my $importer = Catmandu->importerscip-perl cpan Catmandu-MARC 1.32 Catmandu/importer().(
41 'MARC',
42 file => \$mrc,
43 type => 'XML',
44 fix => 'marc_cut(001,cntrl)'
45 );
46 my $record = $importer->firstscip-perl cpan Catmandu-MARC 1.32 Catmandu/first().;
47
48 is_deeplyscip-perl cpan Catmandu-MARC 1.32 main/is_deeply(). $record->{cntrl},
49 [
50 {
51 tag => '001',
52 ind1 => ' ',
53 ind2 => ' ',
54 content => " 92005291 "
55 }
56 ], 'marc_cut(001,cntrl)';
57
58 ok ! marc_hasscip-perl cpan Catmandu-MARC 1.32 main/marc_has().($record,'001') , '001 deleted';
59 }
60
61 notescip-perl cpan Catmandu-MARC 1.32 main/note(). 'marc_cut(245,title)';
62 {
63 my $importer = Catmandu->importerscip-perl cpan Catmandu-MARC 1.32 Catmandu/importer().(
64 'MARC',
65 file => \$mrc,
66 type => 'XML',
67 fix => 'marc_cut(245,title)'
68 );
69 my $record = $importer->firstscip-perl cpan Catmandu-MARC 1.32 Catmandu/first().;
70 is_deeplyscip-perl cpan Catmandu-MARC 1.32 main/is_deeply(). $record->{title},
71 [
72 {
73 tag => '245',
74 ind1 => '1',
75 ind2 => '0',
76 subfields => [
77 { a => 'Title / '},
78 { c => 'Name' },
79 ]
80 }
81 ], 'marc_map(245,title)';
82
83 ok ! marc_hasscip-perl cpan Catmandu-MARC 1.32 main/marc_has().($record,'245') , '245 deleted';
84 }
85
86 notescip-perl cpan Catmandu-MARC 1.32 main/note(). 'marc_cut(245a,title)';
87 {
88 my $importer = Catmandu->importerscip-perl cpan Catmandu-MARC 1.32 Catmandu/importer().(
89 'MARC',
90 file => \$mrc,
91 type => 'XML',
92 fix => 'marc_cut(245a,title)'
93 );
94 my $record = $importer->firstscip-perl cpan Catmandu-MARC 1.32 Catmandu/first().;
95 is_deeplyscip-perl cpan Catmandu-MARC 1.32 main/is_deeply(). $record->{title},
96 [
97 {
98 tag => '245',
99 ind1 => '1',
100 ind2 => '0',
101 subfields => [
102 { a => 'Title / '},
103 { c => 'Name' },
104 ]
105 }
106 ], 'marc_map(245a,title)';
107 ok ! marc_hasscip-perl cpan Catmandu-MARC 1.32 main/marc_has().($record,'245') , '245 deleted';
108 }
109
110 notescip-perl cpan Catmandu-MARC 1.32 main/note(). 'marc_cut(245x,title)';
111 {
112 my $importer = Catmandu->importerscip-perl cpan Catmandu-MARC 1.32 Catmandu/importer().(
113 'MARC',
114 file => \$mrc,
115 type => 'XML',
116 fix => 'marc_cut(245x,title)'
117 );
118 my $record = $importer->firstscip-perl cpan Catmandu-MARC 1.32 Catmandu/first().;
119 is_deeplyscip-perl cpan Catmandu-MARC 1.32 main/is_deeply(). $record->{title},
120 [
121 ], 'marc_map(245x,title)';
122 okscip-perl cpan Catmandu-MARC 1.32 main/ok(). marc_hasscip-perl cpan Catmandu-MARC 1.32 main/marc_has().($record,'245') , '245 still exists';
123 }
124
125 notescip-perl cpan Catmandu-MARC 1.32 main/note(). 'marc_cut(245a,title,equals:"Title / ")';
126 {
127 my $importer = Catmandu->importerscip-perl cpan Catmandu-MARC 1.32 Catmandu/importer().(
128 'MARC',
129 file => \$mrc,
130 type => 'XML',
131 fix => 'marc_cut(245a,title,equals:"Title / ");'
132 );
133 my $record = $importer->firstscip-perl cpan Catmandu-MARC 1.32 Catmandu/first().;
134 is_deeplyscip-perl cpan Catmandu-MARC 1.32 main/is_deeply(). $record->{title},
135 [
136 {
137 tag => '245',
138 ind1 => '1',
139 ind2 => '0',
140 subfields => [
141 { a => 'Title / '},
142 { c => 'Name' },
143 ]
144 }
145 ], 'marc_map(245a,title,equals:"Title / ")';
146 ok ! marc_hasscip-perl cpan Catmandu-MARC 1.32 main/marc_has().($record,'245') , '245 deleted';
147 }
148
149 notescip-perl cpan Catmandu-MARC 1.32 main/note(). 'marc_cut(999,local)';
150 {
151 my $importer = Catmandu->importerscip-perl cpan Catmandu-MARC 1.32 Catmandu/importer().(
152 'MARC',
153 file => \$mrc,
154 type => 'XML',
155 fix => 'marc_cut(999,local)'
156 );
157 my $record = $importer->firstscip-perl cpan Catmandu-MARC 1.32 Catmandu/first().;
158 is_deeplyscip-perl cpan Catmandu-MARC 1.32 main/is_deeply(). $record->{local},
159 [
160 {
161 tag => '999',
162 ind1 => ' ',
163 ind2 => ' ',
164 subfields => [
165 { a => 'X'},
166 { a => 'Y'}
167 ]
168 },
169 {
170 tag => '999',
171 ind1 => ' ',
172 ind2 => ' ',
173 subfields => [
174 { a => 'Z'}
175 ]
176 }
177 ], 'marc_cut(999,local)';
178 ok ! marc_hasscip-perl cpan Catmandu-MARC 1.32 main/marc_has().($record,'999') , '999 deleted';
179 }
180
181 notescip-perl cpan Catmandu-MARC 1.32 main/note(). 'marc_cut(...,all)';
182 {
183 my $importer = Catmandu->importerscip-perl cpan Catmandu-MARC 1.32 Catmandu/importer().(
184 'MARC',
185 file => \$mrc,
186 type => 'XML',
187 fix => 'marc_cut(...,all);'
188 );
189 my $record = $importer->firstscip-perl cpan Catmandu-MARC 1.32 Catmandu/first().;
190 is_deeplyscip-perl cpan Catmandu-MARC 1.32 main/is_deeply(). $record->{all},
191 [
192 {
193 tag => 'LDR',
194 ind1 => ' ',
195 ind2 => ' ',
196 content => " "
197 },
198 {
199 tag => '001',
200 ind1 => ' ',
201 ind2 => ' ',
202 content => " 92005291 "
203 },
204 {
205 tag => '245',
206 ind1 => '1',
207 ind2 => '0',
208 subfields => [
209 { a => 'Title / '},
210 { c => 'Name' },
211 ]
212 },
213 {
214 tag => '999',
215 ind1 => ' ',
216 ind2 => ' ',
217 subfields => [
218 { a => 'X'},
219 { a => 'Y'}
220 ]
221 },
222 {
223 tag => '999',
224 ind1 => ' ',
225 ind2 => ' ',
226 subfields => [
227 { a => 'Z'}
228 ]
229 }
230 ], 'marc_cut(...,all)';
231
232 is_deeplyscip-perl cpan Catmandu-MARC 1.32 main/is_deeply(). $record->{record} , [] , 'marc record is empty';
233 }
234
235 done_testing;
236
237 sub marc_hasscip-perl cpan Catmandu-MARC 1.32 main/marc_has(). {
238 my ($record,$tag) = @_scip-perl cpan Catmandu-MARC 1.32 main/`@_`.;
239 for (@{$record->{record}}) {
240 return 1 if $_scip-perl cpan Catmandu-MARC 1.32 main/$_.->[0] eq $tag;
241 }
242 return 0;
243 }