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