1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use Test::More tests => 104; |
use Test::More tests => 123; |
4 |
use Test::Exception; |
use Test::Exception; |
5 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
6 |
use blib; |
use blib; |
11 |
BEGIN { |
BEGIN { |
12 |
use_ok( 'WebPAC::Input::ISIS' ); |
use_ok( 'WebPAC::Input::ISIS' ); |
13 |
use_ok( 'WebPAC::Input::MARC' ); |
use_ok( 'WebPAC::Input::MARC' ); |
14 |
|
use_ok( 'WebPAC::Input::Test' ); |
15 |
} |
} |
16 |
|
|
17 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
18 |
my $no_log = $debug ? 0 : 1; |
my $no_log = $debug ? 0 : 1; |
19 |
|
|
20 |
ok(my $abs_path = abs_path($0), "abs_path"); |
ok(my $abs_path = abs_path($0), "abs_path"); |
21 |
$abs_path =~ s#/[^/]*$#/#; |
$abs_path =~ s#/[^/]*$#/#; #vim |
22 |
|
|
23 |
my $module = 'WebPAC::Input::ISIS'; |
my $module = 'WebPAC::Input::ISIS'; |
24 |
diag "testing with $module"; |
diag "testing with $module"; |
25 |
|
|
26 |
throws_ok { my $input = new WebPAC::Input( ) } qr/module/, "need module"; |
throws_ok { my $input = new WebPAC::Input( no_log => $no_log ) } qr/module/, "need module"; |
27 |
ok(my $input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, stats => 1 ), "new $module"); |
ok(my $input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, stats => 1 ), "new $module"); |
28 |
ok(my $input_lm = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module"); |
ok(my $input_lm = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module"); |
29 |
|
|
79 |
cmp_ok($input->pos, '==', $mfn, "pos $mfn"); |
cmp_ok($input->pos, '==', $mfn, "pos $mfn"); |
80 |
push @db, $rec; |
push @db, $rec; |
81 |
ok(my $dump = $input->dump_ascii, "dump_ascii $mfn"); |
ok(my $dump = $input->dump_ascii, "dump_ascii $mfn"); |
82 |
|
# XXX test count will help us keep this test in-line :-) |
83 |
|
ok($rec->{leader}, "leader $mfn") if $rec->{leader}; |
84 |
diag $dump if ($debug); |
diag $dump if ($debug); |
85 |
} |
} |
86 |
|
|
122 |
test_fetch($input, $input->size); |
test_fetch($input, $input->size); |
123 |
|
|
124 |
# test modify_record |
# test modify_record |
125 |
$module = 'WebPAC::Input::ISIS'; |
$module = 'WebPAC::Input::Test'; |
126 |
ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module"); |
ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, debug => $debug ), "new $module"); |
127 |
|
|
128 |
|
$WebPAC::Input::Test::rec = { |
129 |
|
'200' => [ |
130 |
|
{ 'a' => '[200 a]', 'b' => '[200 b]', 'c' => '[200 c]', 'f' => '[200 f] test : test' }, |
131 |
|
], |
132 |
|
'900' => [ |
133 |
|
{ 'x' => 'foobar', }, |
134 |
|
], |
135 |
|
}; |
136 |
|
|
137 |
|
$WebPAC::Input::Test::size = 42; |
138 |
|
|
139 |
|
ok($input->open( path => "/fake/path", ), "open modify_isis (plain)"); |
140 |
|
|
141 |
|
cmp_ok($input->size, '==', 42, 'size'); |
142 |
|
|
|
ok($input->open( path => "$abs_path/modify_isis/LIBRI", ), "open modify_isis (plain)"); |
|
143 |
ok(my $rec_p = $input->fetch, 'fetch'); |
ok(my $rec_p = $input->fetch, 'fetch'); |
144 |
|
|
145 |
# modify_records |
# modify_records |
146 |
|
|
147 |
ok($input->open( |
ok($input->open( |
148 |
path => "$abs_path/modify_isis/LIBRI", |
path => "/another/fake/path", |
149 |
modify_records => { |
modify_records => { |
150 |
200 => { |
200 => { |
151 |
'*' => { '^c' => '. ' }, |
'*' => { '^c' => '. ' }, |
152 |
'^f' => { ' : ' => ' / ' }, |
'^f' => { ' : ' => ' / ' }, |
153 |
} |
} |
154 |
}, |
}, |
155 |
), "open modify_isis (with modify_records)"); |
), "open (with modify_records)"); |
156 |
|
|
157 |
ok(my $rec = $input->fetch, 'fetch'); |
# seek |
158 |
diag "fetched rec field 200 = ", dump($rec->{200}) if ($debug); |
throws_ok { $input->seek } qr/without/, 'seek without position'; |
159 |
|
cmp_ok($input->seek(0), '==', -1, 'seek'); |
160 |
|
|
161 |
cmp_ok($rec_p->{200}->[0]->{f} . '. ' . $rec_p->{200}->[0]->{c}, 'eq' ,$rec->{200}->[0]->{f}, 'modify_records working'); |
sub test_filter { |
162 |
|
|
163 |
diag "input = ",dump($input->{data}) if ($debug); |
my $f = $WebPAC::Input::Test::filter_coderef; |
164 |
|
ok(ref($f) eq 'CODE', 'filter_coderef'); |
165 |
|
|
166 |
# break encapsulation, bad! bad! |
my ($field, $from, $to) = @_; |
167 |
$input->{ll_db}->{_isis_db}->{record} = { |
cmp_ok( $f->( $from, $field, 1 ), 'eq', $to, "filter $field |$from| -> |$to|" ); |
168 |
900 => 'foo ; bar ; baz', |
} |
|
}; |
|
169 |
|
|
170 |
$input->{modify_record} = { |
test_filter(200, |
171 |
900 => { |
'^afoo^cbar^fbing : bong', |
172 |
'*' => [ |
'^afoo. bar^fbing / bong', |
173 |
{ ' ; ' => 'a' }, |
); |
|
{ ' ; ' => 'b' }, |
|
|
{ ' ; ' => 'c' }, |
|
|
], |
|
|
} |
|
|
}; |
|
174 |
|
|
175 |
diag "hacked: ",dump($input, $input->fetch) if ($debug); |
# modify_file |
176 |
|
|
177 |
# seek |
my $modify_file = "$abs_path/conf/modify/test.pl"; |
178 |
throws_ok { $input->seek } qw/without/, 'seek without position'; |
|
179 |
cmp_ok($input->seek(0), '==', -1, 'seek'); |
ok($input->open( |
180 |
|
path => "/and/another/fake/path", |
181 |
|
modify_file => $modify_file, |
182 |
|
), "open (with modify_file $modify_file)"); |
183 |
|
|
184 |
|
diag "regexps = ", dump($input->modify_file_regexps( $modify_file )) if ($debug); |
185 |
|
|
186 |
|
test_filter(200, |
187 |
|
'^a foo ; bar = baz : zzz', |
188 |
|
'^a foo^kbar^dbaz : zzz', |
189 |
|
); |
190 |
|
|
191 |
|
# empty subfield removal |
192 |
|
|
193 |
|
ok($input->open( |
194 |
|
path => "/another/fake/path", |
195 |
|
modify_records => { |
196 |
|
900 => { |
197 |
|
'^a' => { '^e' => ' : ^e' }, |
198 |
|
}, |
199 |
|
901 => { |
200 |
|
'^a' => { 'foo' => 'baz' }, |
201 |
|
}, |
202 |
|
}, |
203 |
|
), "open (with modify_records for empty subfields)"); |
204 |
|
|
205 |
ok(my $rec = $input->fetch, 'fetch'); |
test_filter(900, |
206 |
diag "fetched rec = ", dump($rec) if ($debug); |
'^a^ebar', |
207 |
|
'^a^ebar', |
208 |
|
); |
209 |
|
|
210 |
|
test_filter(900, |
211 |
|
'^afoo^ebar', |
212 |
|
'^afoo : ^ebar', |
213 |
|
); |
214 |
|
|
215 |
|
test_filter(901, |
216 |
|
'^afoo^ebar', |
217 |
|
'^abaz^ebar', |
218 |
|
); |