]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t
Add test to confirm that holdings fields are defined for each
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Utils / MFHD / test / mfhd.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Data::Dumper;
6 use Test::More 'no_plan';
7
8 use MARC::Record;
9 use OpenILS::Utils::MFHD;
10
11 my $testno = 0;
12
13 sub right_answer {
14     my $holding = shift;
15     my $answer  = {};
16
17     foreach my $subfield (split(/\|/, $holding->subfield('x'))) {
18         next unless $subfield;
19
20         my ($key, $val) = unpack('aa*', $subfield);
21         $answer->{$key} = $val;
22     }
23
24     return $answer;
25 }
26
27 sub load_MARC_rec {
28     my $rec;
29     my $line;
30     my $marc = undef;
31
32     # skim to beginning of record (a non-blank, non comment line)
33     while ($line = <DATA>) {
34         chomp $line;
35         last if (!($line =~ /^\s*$/) && !($line =~ /^#/));
36     }
37
38     return undef if !$line;
39
40     $testno += 1;
41     $marc = MARC::Record->new();
42     carp('No record created!') unless $marc;
43
44     $marc->leader('01119nas  2200313 a 4500');
45     $marc->append_fields(
46         MARC::Field->new('008', '970701c18439999enkwr p       0   a0eng  '));
47     $marc->append_fields(
48         MARC::Field->new('035', '', '', a => sprintf('%04d', $testno)));
49
50     while ($line) {
51         next if $line =~ /^#/;    # allow embedded comments
52
53         return $marc if $line =~ /^\s*$/;
54
55         my ($fieldno, $indicators, $rest) = split(/ /, $line, 3);
56         my @inds = unpack('aa', $indicators);
57         my $field;
58         my @subfields;
59
60         @subfields = ();
61         foreach my $subfield (split(/\$/, $rest)) {
62             next unless $subfield;
63
64             my ($key, $val) = unpack('aa*', $subfield);
65             push @subfields, $key, $val;
66         }
67
68         $field = MARC::Field->new(
69             $fieldno, $inds[0], $inds[1],
70             a => 'scratch',
71             @subfields
72         );
73
74         $marc->append_fields($field);
75
76         $line = <DATA>;
77         chomp $line if $line;
78     }
79     return $marc;
80 }
81
82 my $rec;
83 my @captions;
84
85 while ($rec = load_MARC_rec) {
86     $rec = MFHD->new($rec);
87
88     foreach my $cap (sort { $a->tag <=> $b->tag } $rec->field('85.')) {
89         my $htag;
90         my @holdings;
91
92         ($htag = $cap->tag) =~ s/^85/86/;
93         @holdings = $rec->holdings($htag, $cap->subfield('8'));
94
95         ok(scalar @holdings, "holdings defined " . $cap->subfield('8'));
96
97         foreach my $field (@holdings) {
98           TODO: {
99                 local $TODO = "unimplemented"
100                   if ($field->subfield('z') =~ /^TODO/);
101                 is_deeply($field->next, right_answer($field),
102                     $field->subfield('8') . ': ' . $field->subfield('z'));
103             }
104         }
105     }
106 }
107
108 1;
109
110 __END__
111 #
112 # load record, then loop over 863 fields calling next().
113 #
114
115 245 00 $aMonthly, issue no. restarts, calendar change: Jan
116 853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
117 863 41 $81.1$a1$b6$i1990$j06$x|a1|b7|i1990|j07$zMiddle of year, middle of vol.
118 863 41 $81.2$a1$b11$i1990$j11$x|a1|b12|i1990|j12$zEnd of year, end of vol.
119 863 41 $81.3$a1$b12$i1990$j12$x|a2|b1|i1991|j01$zWrap at end of year/vol.
120
121 245 00 $aMonthly, issue no. restarts, calendar change: Mar
122 853 20 $82$av.$bno.$u12$vr$i(year)$j(month)$wm$x03
123 863 41 $82.1$a1$b6$i1990$j08$x|a1|b7|i1990|j09$zMiddle of year, middle of vol.
124 863 41 $82.2$a1$b10$i1990$j12$x|a1|b11|i1991|j01$zEnd of year, middle of vol.
125 863 41 $82.3$a1$b11$i1991$j01$x|a1|b12|i1991|j02$zMiddle of year, end of vol.
126 863 41 $82.3$a1$b12$i1991$j02$x|a2|b1|i1991|j03$zWrap vol in mid-year
127
128 245 00 $aMonthly, issue no. continuous, calendar change: Jan
129 853 20 $83$av.$bno.$u12$vc$i(year)$j(month)$wm$x01
130 863 41 $83.1$a1$b6$i1990$j06$x|a1|b7|i1990|j07$zMiddle of year, middle of vol.
131 863 41 $83.2$a1$b11$i1990$j11$x|a1|b12|i1990|j12$zEnd of year, end of vol.
132 863 41 $83.3$a1$b12$i1990$j12$x|a2|b13|i1991|j01$zwrap vol @ end of year
133
134 245 00 $aMonthly, issue no. continuous, calendar change: Mar
135 853 20 $84$av.$bno.$u12$vc$i(year)$j(month)$wm$x03
136 863 41 $84.1$a1$b6$i1990$j08$x|a1|b7|i1990|j09$zMiddle of year, middle of vol.
137 863 41 $84.2$a1$b10$i1990$j12$x|a1|b11|i1991|j01$zEnd of year, middle of vol.
138 863 41 $84.3$a1$b11$i1991$j01$x|a1|b12|i1991|j02$zMiddle of year, end of vol.
139 863 41 $84.4$a1$b12$i1991$j02$x|a2|b13|i1991|j03$zwrap vol mid-year
140
141 245 00 $aMonthly, issue no. restarts, Calendar change: Jan, Jul
142 853 20 $85$av.$bno.$u6$vr$i(year)$j(month)$wm$x01,07
143 863 41 $85.1$a1$b5$i1990$j05$x|a1|b6|i1990|j06$zMiddle of year, near end of vol.
144 863 41 $85.2$a1$b6$i1990$j06$x|a2|b1|i1990|j07$zMiddle of year, end of vol.
145 863 41 $85.3$a2$b6$i1990$j12$x|a3|b1|i1991|j01$zEnd of year, end of vol.
146
147 245 00 $aMonthly, issue no. continuous, Calendar change: Jan, Jul
148 853 20 $86$av.$bno.$u6$vc$i(year)$j(month)$wm$x01,07
149 863 41 $86.1$a1$b5$i1990$j05$x|a1|b6|i1990|j06$zMiddle of year, end of vol.
150 863 41 $86.2$a1$b6$i1990$j06$x|a2|b7|i1990|j07$zMiddle of year, end of vol.
151 863 41 $86.3$a2$b12$i1990$j12$x|a3|b13|i1991|j01$zEnd of year, end of vol.
152
153 245 00 $aMonthly, issue no. restarts, Calendar change: Jan, Combined issue: Jan/Feb
154 853 20 $87$av.$bno.$u11$vr$i(year)$j(month)$wm$x01$ycm01/02
155 863 41 $87.1$a1$b11$i1990$j12$x|a2|b1|i1991|j01/02$z End of year, end of vol.
156 863 41 $87.2$a2$b1$i1991$j01/02$x|a2|b2|i1991|j03$z Beginning of year, beginning of vol.
157
158 245 00 $aMonthly, iss no. restarts, Calendar change: Jan, Combined iss: Nov/Dec
159 853 20 $88$av.$bno.$u11$vr$i(year)$j(month)$wm$x01$ycm11/12
160 863 41 $88.1$a1$b10$i1990$j10$x|a1|b11|i1990|j11/12$z end of year, end of vol.
161 863 41 $88.2$a1$b11$i1990$j11/12$x|a2|b1|i1991|j01$z wrap vol at year end
162
163 245 00 $aMonthly, iss no. restarts, Cal. change: Jan, Combined iss: Jan/Feb, Nov/Dec
164 853 20 $89$av.$bno.$u10$vr$i(year)$j(month)$wm$x01$ycm01/02,11/12
165 863 41 $89.1$a1$b1$i1990$j01/02$x|a1|b2|i1990|j03$z beg. of year, beg. of vol.
166 863 41 $89.2$a1$b9$i1990$j10$x|a1|b10|i1990|j11/12$z end of year, end of vol.
167 863 41 $89.3$a1$b10$i1990$j11/12$x|a2|b1|i1991|j01/02$z zwrap vol at year end
168
169 245 00 $aMonthly, iss no. restarts, Cal. change: Jan, Combined iss: May/Jun, Jul/Aug
170 853 20 $810$av.$bno.$u10$vr$i(year)$j(month)$wm$x01$ycm05/06,07/08
171 863 41 $810.1$a1$b4$i1990$j04$x|a1|b5|i1990|j05/06$z next iss is combined.
172 863 41 $810.2$a1$b5$i1990$j05/06$x|a1|b6|i1990|j07/08$z combined to combined
173 863 41 $810.3$a1$b6$i1990$j07/08$x|a1|b7|i1990|j09$z combined to reg
174
175 245 00 $aMonthly, issue no. restarts, Calendar change: Jan, Combined issue: 1/2 Jan/Feb 
176 853 20 $811$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm01/02$yce21/2
177 863 41 $811.1$a1$b12$i1990$j12$x|a2|b1/2|i1991|j01/02$znew vol at year end regular iss to combined
178 863 41 $811.2$a2$b1/2$i1991$j01/02$x|a2|b3|i1991|j03$zcombined iss to regular
179
180 245 00 $aMonthly, iss no. restarts, Calendar change: Jan, Combined iss: 11/12 Nov/Dec
181 853 20 $812$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm11/12$yce211/12
182 863 41 $812.1$a1$b10$i1990$j10$x|a1|b11/12|i1990|j11/12$zregular to combined iss
183 863 41 $812.2$a1$b11/12$i1990$j11/12$x|a2|b1|i1991|j01$zend of vol: combined to regular issue
184
185 245 00 $aMonthly, iss no. restarts, Cal. change: Jan, Combined iss: 1/2 Jan/Feb, 11/12 Nov/Dec
186 853 20 $813$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm01/02,11/12$yce21/2,11/12
187 863 41 $813.1$a1$b10$i1990$j10$x|a1|b11/12|i1990|j11/12$zend of vol regular to combined iss
188 863 41 $813.2$a1$b11/12$i1990$j11/12$x|a2|b1/2|i1991|j01/02$zwrap at volume end: combined to combined
189 863 41 $813.3$a2$b1/2$i1991$j01/02$x|a2|b3|i1991|j03$zbeginning of vol: combined to regular
190
191 245 00 $aMonthly, iss no. restarts, Cal. change: Jan, Combined iss: 5/6 May/Jun, 7/8 Jul/Aug 
192 853 20 $814$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm05/06,07/08$yce25/6,7/8
193 863 41 $814.1$a1$b4$i1990$j04$x|a1|b5/6|i1990|j05/06$zmid year: reg to combined
194 863 41 $814.2$a1$b5/6$i1990$j05/06$x|a1|b7/8|i1990|j07/08$zmid year: combined to combined
195 863 41 $814.3$a1$b7/8$i1990$j07/08$x|a1|b9|i1990|j09$zmid year: combined to regular
196
197 245 00 $aMonthly, iss no. restarts, Cal change: Jan, July issue omitted
198 853 20 $815$av.$bno.$u11$vr$i(year)$j(month)$wm$x01$yom07
199 863 41 $815.1$a1$b6$i1990$j06$x|a1|b7|i1990|j08$zskip july issue
200
201 245 00 $aQuarterly, chronology in enumeration fields
202 853 20 $816$a(year)$b(season)$wq$yps21,22,23,24
203 863 41 $816.1$a2007$b21$x|a2007|b22$zChron in enum: simple case: quarterly in mid-volume
204 863 41 $816.2$a2007$b24$x|a2008|b21$zChron in enum: Roll over to new year
205
206 245 00 $aFour issues a year, chronology in enum fields, combined Sum/Fall issue
207 853 20 $817$a(year)$b(season)$wq$ycs22/23
208 863 41 $817.1$a2007$b21$x|a2007|b22/23$zChron in enum: Spring to Summer/Fall
209 863 41 $817.2$a2007$b22/23$x|a2007|b24$zChron in enum: Summer/Fall to Winter
210
211 245 00 $aLibrary Journal: 20 times a year, semimonthly except Jan, Jul, Aug, Dec
212 853 20 $818$av.$bno.$u20$vr$i(year)$j(month)$k(day)$ws$x01$ypd01,15$yod0115,0715,0815,1215
213 863 41 $818.1$a132$b20$i2007$j12$k1$x|a133|b1|i2008|j01|k01$zSkipping over missed date to beginning of next year/volume.
214 863 41 $818.2$a133$b1$i2008$j01$k01$x|a133|b2|i2008|j02|k01$zSkipping over missed date at beginning of year
215 863 41 $818.3$a133$b2$i2008$j02$k01$x|a133|b3|i2008|j02|k15$zPublished semimonthly, going from 1st to 15th
216 863 41 $818.4$a133$b3$i2008$j02$k15$x|a133|b4|i2008|j03|k01$zPublished semimonthly, going from 15th to 1st
217
218 245 00 $aBimonthly: Feb, Apr, June, Aug, Oct, Dec
219 853 20 $819$av.$bno.$u6$vr$i(year)$j(month)$wb$x02$ypm02,04,06,08,10,12
220 863 41 $819.1$a1$b3$i1990$j06$x|a1|b4|i1990|j08$zMiddle of year, middle of vol.
221 863 41 $819.2$a1$b5$i1990$j10$x|a1|b6|i1990|j12$zEnd of year, end of vol.
222 863 41 $819.3$a1$b6$i1990$j12$x|a2|b1|i1991|j02$zWrap at end of year/vol.
223
224 245 00 $aBimonthly, published 5 times with combined summer issue: Feb, Apr, June/Aug, Oct, Dec
225 853 20 $820$av.$bno.$u5$vr$i(year)$j(month)$wb$x02$ypm02,04,10,12$ycm06/08
226 863 41 $820.1$a1$b2$i1990$j04$x|a1|b3|i1990|j06/08$zFrom Apr to Jun/Aug
227 863 41 $820.2$a1$b3$i1990$j06/08$x|a1|b4|i1990|j10$zFrom Jun/Aug to Oct
228 863 41 $820.3$a1$b5$i1990$j12$x|a2|b1|i1991|j02$zWrap at end of year/vol.
229
230 245 00 $aEconomist: pub. w on Sa, except combined iss on last two weeks of year
231 853 20 $821$av.$bno.$u12$vc$i(year)$j(month)$k(day)$ww$x01,04,07,10$ypdsa$yow1299
232 863 41 $821.1$a100$b1200$i2008$j12$k06$x|a100|b1201|i2008|j12|k13$zwithin vol.
233 863 41 $821.2$a100$b1201$i2008$j12$k13$x|a100|b1202|i2008|j12|k20$zwithin vol. combined iss.
234 863 41 $821.3$a100$b1202$i2008$j12$k20$x|a101|b1203|i2009|j01|k03$zvolume change over omitted iss.
235
236 245 00 $aMFHD example: monthly, pub. 2nd Wed of month except in April: 2nd Thu; May:1st Wednesday.
237 853 20 $822$av.$bno.$u12$vr$i(year)$j(month)$k(day)$wm$x01$ypw02we$ypw0402th,0501we$yow0402we,0502we
238 863 41 $822.1$a1$b2$i2009$j02$k11$x|a1|b3|i2009|j03|k11$zpublished on 2nd Wed in Mar
239 863 41 $822.2$a1$b3$i2009$j03$k11$x|a1|b4|i2009|j04|k09$zpublished on 2nd Thu in Apr
240 863 41 $822.3$a1$b4$i2009$j04$k09$x|a1|b5|i2009|j05|k06$zpublished on 1st Wed in May
241 863 41 $822.4$a2$b4$i2013$j04$k11$x|a2|b5|i2013|j05|k01$zpublished on Wed May 1st
242
243 245 00 $aMFHD example: pub. every Mon, Thu, except on New Years, July 4, Labor Day, Thanksgiving, Christmas
244 853 20 $823$av.$bno.$uvar$vr$i(year)$j(month)$k(day)$wc$x07$ypw00mo,00th$yod0101,0704,1225$yow0901mo,1104th
245 863 41 $823.1$a1$b100$i2009$j02$k02$x|a1|b101|i2009|j02|k05$znormal: Mon to Thu
246 863 41 $823.2$a1$b101$i2009$j02$k05$x|a1|b102|i2009|j02|k09$znormal: Thu to Mon
247 863 41 $823.3$a1$b150$i2009$j06$k29$x|a2|b151|i2009|j07|k02$znormal: calendar change
248 863 41 $823.4$a2$b180$i2009$j09$k03$x|a2|b181|i2009|j09|k10$zSkip Labor Day
249 863 41 $823.5$a2$b200$i2009$j11$k23$x|a2|b201|i2009|j11|k30$zSkip (US) Thanksgiving
250
251 #
252 # According to the specification and the examples at
253 # http://www.loc.gov/marc/chrono_patterns.html it is possible to
254 # document a combined issue in a $yp publication regularity definition,
255 # like this: $yps21,22/23,24
256 245 00 $aCombined date documented in publication pattern rather than combined pattern
257 853 20 $824$av.$bno.$u3$vr$i(year)$j(season)$wq$x21$yps21,22/23,24
258 863 41 $824.1$a1$b1$i2009$j21$x|a1|b2|i2009|j22/23$zSpring to Summer/Fall
259 863 41 $824.2$a1$b2$i2009$j22/23$x|a1|b3|i2009|j24$zSummer/Fall to Winter
260
261 # Item is published 6 times/year whose enumeration "skips" numbers
262 # at the second level using only odd numbers that restart
263 # at the turn of the calendar year.
264 # (From www.loc.gov/marc/chrono_patterns.html)
265 245 00 $aFunky enumeration
266 853 20 $825$av.$bno.$u6$vr$i(year)$j(month)$wb$ype21,3,5,7,9,11
267 863 41 $825.1$a1$b1$i1990$j01$x|a1|b3|i1990|j03$zJan to Mar
268 863 41 $825.2$a1$b11$i1990$j11$x|a2|b1|i1991|j01$zNov to Jan, year & vol wrap
269
270
271 # Monthly, one volume per year, issue numbering restarts in January
272 # Annual supplement published in September, annual index published in
273 # February
274 245 00 $aSupplements and Indexes: Oh My
275 853 20 $826$av.$bno.$u12$vr$i(year)$j(month)$wm
276 854 20 $827$av.$i(year)$j(month)$wa$ypm09$oSupplement
277 855 20 $828$av.$i(year)$j(month)$ypm02$oIndex
278 863 41 $826.1$a1$b1$i1990$j01$x|a1|b2|i1990|j02$znormal issue
279 864 41 $827.1$a1$i1990$j09$x|a2|i1991|j09$zAnnual supplement
280 865 41 $828.1$a1$i1990$j02$x|a2|i1991|j02$zAnnual Index