3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Test::More tests => 134; |
use Test::More tests => 136; |
7 |
use File::Spec; |
use File::Spec; |
8 |
|
|
9 |
BEGIN { |
BEGIN { |
271 |
], |
], |
272 |
902 => [{ a => "a1 ; a2 ; a3 ; a4 ; a5", b => "b1 ; b2", c => "c1" }], |
902 => [{ a => "a1 ; a2 ; a3 ; a4 ; a5", b => "b1 ; b2", c => "c1" }], |
273 |
}, 'hash is_deeply'); |
}, 'hash is_deeply'); |
274 |
|
|
275 |
|
# split_on_delimiters |
276 |
|
|
277 |
|
$isis->{record} = { |
278 |
|
900 => [ '^a900a : 900b ; 900c' ], |
279 |
|
901 => [ |
280 |
|
'^a901a-1 x 901b-1 y 901c-1', |
281 |
|
'^b901b-2 x 901b-2', |
282 |
|
'^c901c-3 y 901c-3', |
283 |
|
], |
284 |
|
}; |
285 |
|
|
286 |
|
my $split_on_delimiters = { |
287 |
|
900 => { a => { ' : ' => 'b', ' ; ' => 'c' } }, |
288 |
|
901 => { |
289 |
|
a => { ' x ' => 'b', ' y ' => 'c' }, |
290 |
|
b => { ' x ' => 'b' }, |
291 |
|
c => { ' y ' => 'c' } |
292 |
|
}, |
293 |
|
}; |
294 |
|
|
295 |
|
diag "split_on_delimiters = ", Dumper($split_on_delimiters); |
296 |
|
|
297 |
|
my $regexpes; |
298 |
|
|
299 |
|
foreach my $f (keys %$split_on_delimiters) { |
300 |
|
warn "--- f: $f\n"; |
301 |
|
foreach my $sf (keys %{ $split_on_delimiters->{$f} }) { |
302 |
|
warn "---- sf: $sf\n"; |
303 |
|
foreach my $patt (keys %{ $split_on_delimiters->{$f}->{$sf} }) { |
304 |
|
my $new_sf = $split_on_delimiters->{$f}->{$sf}->{$patt} || die "no field?"; |
305 |
|
warn "----- patt: $patt -> $new_sf\n"; |
306 |
|
|
307 |
|
# fool-proof spaces in pattern |
308 |
|
$patt =~ s/\s+/\\s\+/g; |
309 |
|
|
310 |
|
push @{ $regexpes->{$f} }, |
311 |
|
's/\^' . $sf . '([^\^]+)' . $patt . '([^\^]+)/^' . $sf . '$1^' . $new_sf . '$2/g'; |
312 |
|
} |
313 |
|
} |
314 |
|
} |
315 |
|
|
316 |
|
diag "generated regexpes = ", Dumper( $regexpes ); |
317 |
|
|
318 |
|
|
319 |
|
ok($hash = $isis->to_hash({ mfn => $isis->mfn, regexps => $regexpes, }), 'to_hash(mfn,regexpes)'); |
320 |
|
diag "to_hash = ",Dumper( $hash ) if ($debug); |
321 |
|
is_deeply( $hash, { |
322 |
|
"000" => [42], |
323 |
|
900 => [{ a => "900a", b => "900b", c => "900c" }], |
324 |
|
901 => [ |
325 |
|
{ a => "901a-1", b => "901b-1", c => "901c-1" }, |
326 |
|
{ b => ["901b-2", "901b-2"] }, |
327 |
|
{ c => ["901c-3", "901c-3"] }, |
328 |
|
], |
329 |
|
}, 'hash is_deeply'); |