1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use Test::More tests => 111; |
use Test::More tests => 116; |
4 |
use Test::Exception; |
use Test::Exception; |
5 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
6 |
use blib; |
use blib; |
134 |
|
|
135 |
$WebPAC::Input::Test::size = 42; |
$WebPAC::Input::Test::size = 42; |
136 |
|
|
137 |
ok($input->open( path => "$abs_path/modify_isis/LIBRI", ), "open modify_isis (plain)"); |
ok($input->open( path => "/fake/path", ), "open modify_isis (plain)"); |
138 |
|
|
139 |
cmp_ok($input->size, '==', 42, 'size'); |
cmp_ok($input->size, '==', 42, 'size'); |
140 |
|
|
143 |
# modify_records |
# modify_records |
144 |
|
|
145 |
ok($input->open( |
ok($input->open( |
146 |
path => "$abs_path/modify_isis/LIBRI", |
path => "/another/fake/path", |
147 |
modify_records => { |
modify_records => { |
148 |
200 => { |
200 => { |
149 |
'*' => { '^c' => '. ' }, |
'*' => { '^c' => '. ' }, |
156 |
throws_ok { $input->seek } qr/without/, 'seek without position'; |
throws_ok { $input->seek } qr/without/, 'seek without position'; |
157 |
cmp_ok($input->seek(0), '==', -1, 'seek'); |
cmp_ok($input->seek(0), '==', -1, 'seek'); |
158 |
|
|
159 |
my $f = $WebPAC::Input::Test::filter_coderef; |
sub test_filter { |
160 |
ok(ref($f) eq 'CODE', 'filter_coderef'); |
|
161 |
|
my $f = $WebPAC::Input::Test::filter_coderef; |
162 |
|
ok(ref($f) eq 'CODE', 'filter_coderef'); |
163 |
|
|
164 |
|
my ($field, $from, $to) = @_; |
165 |
|
cmp_ok( $f->( $from, $field, 1 ), 'eq', $to, "filter $field |$from| -> |$to|" ); |
166 |
|
} |
167 |
|
|
168 |
cmp_ok( |
test_filter(200, |
169 |
$f->( '^afoo^cbar^fbing : bong', 200), |
'^afoo^cbar^fbing : bong', |
170 |
'eq', '^afoo. bar^fbing / bong', |
'^afoo. bar^fbing / bong', |
|
'modify 200' |
|
171 |
); |
); |
172 |
|
|
173 |
# modify_file |
# modify_file |
175 |
my $modify_file = "$abs_path/conf/modify/test.pl"; |
my $modify_file = "$abs_path/conf/modify/test.pl"; |
176 |
|
|
177 |
ok($input->open( |
ok($input->open( |
178 |
path => "$abs_path/modify_isis/LIBRI", |
path => "/and/another/fake/path", |
179 |
modify_file => $modify_file, |
modify_file => $modify_file, |
180 |
), "open (with modify_file $modify_file)"); |
), "open (with modify_file $modify_file)"); |
181 |
|
|
|
my $f = $WebPAC::Input::Test::filter_coderef; |
|
|
ok(ref($f) eq 'CODE', 'filter_coderef'); |
|
|
|
|
182 |
diag "regexps = ", dump($input->modify_file_regexps( $modify_file )) if ($debug); |
diag "regexps = ", dump($input->modify_file_regexps( $modify_file )) if ($debug); |
183 |
|
|
|
sub test_filter { |
|
|
my ($field, $from, $to) = @_; |
|
|
cmp_ok( $f->( $from, $field, 1 ), 'eq', $to, "filter $field |$from| -> |$to|" ); |
|
|
} |
|
|
|
|
184 |
test_filter(200, |
test_filter(200, |
185 |
'^a foo ; bar = baz : zzz', |
'^a foo ; bar = baz : zzz', |
186 |
'^a foo^kbar^dbaz : zzz', |
'^a foo^kbar^dbaz : zzz', |
187 |
); |
); |
188 |
|
|
189 |
|
# empty subfield removal |
190 |
|
|
191 |
|
ok($input->open( |
192 |
|
path => "/another/fake/path", |
193 |
|
modify_records => { |
194 |
|
900 => { |
195 |
|
'^a' => { '^e' => ' : ^e' }, |
196 |
|
} |
197 |
|
}, |
198 |
|
), "open (with modify_records for empty subfields)"); |
199 |
|
|
200 |
|
test_filter(900, |
201 |
|
'^a^ebar', |
202 |
|
'^a^ebar', |
203 |
|
); |
204 |
|
|
205 |
|
test_filter(900, |
206 |
|
'^afoo^ebar', |
207 |
|
'^afoo : ^ebar', |
208 |
|
); |