2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 89; |
use Test::More tests => 107; |
6 |
use Test::Exception; |
use Test::Exception; |
7 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
8 |
use blib; |
use blib; |
148 |
my $eval_t = $t; |
my $eval_t = $t; |
149 |
$eval_t =~ s/[\n\r\s]+/ /gs; |
$eval_t =~ s/[\n\r\s]+/ /gs; |
150 |
$eval_t = substr($eval_t,0,$max_eval_output) . '...' if (length($eval_t) > $max_eval_output); |
$eval_t = substr($eval_t,0,$max_eval_output) . '...' if (length($eval_t) > $max_eval_output); |
151 |
|
$eval_t =~ s/\\/\\\\/gs; |
152 |
|
|
153 |
eval "$t"; |
my $v = eval "$t"; |
154 |
ok(! $@, $@ ? dump_error($@, $t) : "eval: $eval_t"); |
ok(! $@, $@ ? dump_error($@, $t) : "eval: $eval_t"); |
155 |
|
$v; |
156 |
} |
} |
157 |
|
|
158 |
{ |
{ |
399 |
test_s($r) if ($r); |
test_s($r) if ($r); |
400 |
} |
} |
401 |
|
|
402 |
ok(@marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields"); |
ok(my @marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields"); |
403 |
diag dump( \@marc ) if ($debug); |
diag dump( \@marc ) if ($debug); |
404 |
|
diag "expects:\n", dump($struct) if ($debug > 1); |
405 |
is_deeply( \@marc, $struct, $msg ); |
is_deeply( \@marc, $struct, $msg ); |
406 |
} |
} |
407 |
|
|
461 |
[ '900', 1, 0, 'c', '200c-3' ], |
[ '900', 1, 0, 'c', '200c-3' ], |
462 |
], |
], |
463 |
); |
); |
464 |
|
|
465 |
|
test_rec_rules( |
466 |
|
'marc_compose', |
467 |
|
{ '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] }, |
468 |
|
qq{ |
469 |
|
marc_compose('900', |
470 |
|
'c', rec(200,'b'), |
471 |
|
'b', rec(200,'a'), |
472 |
|
'a', rec(200,'c'), |
473 |
|
); |
474 |
|
}, |
475 |
|
[ |
476 |
|
[ '900', ' ', ' ', 'c', 42, 'b', 'foo ; bar', 'a', 'baz' ] |
477 |
|
], |
478 |
|
); |
479 |
|
|
480 |
|
# |
481 |
|
# test rules |
482 |
|
# |
483 |
|
sub test_rule { |
484 |
|
my ($msg, $rec, $rule, $struct) = @_; |
485 |
|
_clean_ds(); |
486 |
|
_set_rec( $rec ); |
487 |
|
$rule =~ s/\\/\\/gs; |
488 |
|
my $r = test_s( $rule ); |
489 |
|
diag "for ", dump($rec), " got:\n", dump($r), "\nexpect:\n" if ($debug > 1); |
490 |
|
diag dump($struct) if ($debug); |
491 |
|
is_deeply( $r, $struct, $msg ); |
492 |
|
} |
493 |
|
|
494 |
|
# test split_rec_on |
495 |
|
test_rule( |
496 |
|
'split_rec_on', |
497 |
|
{ '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] }, |
498 |
|
qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 1) }, |
499 |
|
'foo', |
500 |
|
); |
501 |
|
test_rule( |
502 |
|
'split_rec_on', |
503 |
|
{ '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] }, |
504 |
|
qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 2) }, |
505 |
|
'bar', |
506 |
|
); |
507 |
|
test_rule( |
508 |
|
'split_rec_on no part', |
509 |
|
{ '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] }, |
510 |
|
q! split_rec_on('200','a', qr/\\s*;\\s*/) !, |
511 |
|
[ 'foo', 'bar' ], |
512 |
|
); |
513 |
|
test_rule( |
514 |
|
'split_rec_on no record', |
515 |
|
{}, |
516 |
|
qq{ split_rec_on('200','a', qr/\\s*;\\s*/) }, |
517 |
|
'', |
518 |
|
); |
519 |
|
|
520 |
|
test_rec_rules( |
521 |
|
'marc_compose+split_rec_on', |
522 |
|
{ '200' => [{ a => 'foo ! bar', b => 42, c => 'baz' }] }, |
523 |
|
qq{ |
524 |
|
marc_compose('900', |
525 |
|
'a', split_rec_on(200,'a', qr/\\s*!\\s*/, 1), |
526 |
|
'c', rec(200,'c'), |
527 |
|
'a', split_rec_on(200,'a', qr/\\s*!\\s*/, 2), |
528 |
|
'b', rec(200,'b'), |
529 |
|
); |
530 |
|
}, |
531 |
|
[ |
532 |
|
[ '900', ' ', ' ', |
533 |
|
'a', 'foo', |
534 |
|
'c', 'baz', |
535 |
|
'a', 'bar', |
536 |
|
'b', 42, |
537 |
|
] |
538 |
|
], |
539 |
|
); |
540 |
|
|
541 |
|
cmp_ok(marc_leader('06',42), '==', 42, 'marc_leader'); |
542 |
|
cmp_ok(marc_leader('11',5), '==', 5, 'marc_leader'); |
543 |
|
ok(marc_leader(), 'marc_leader get'); |
544 |
|
diag "leader: ", dump(marc_leader()) if ($debug); |
545 |
|
is_deeply(marc_leader(), { '06' => 42, 11 => 5 }, "marc_leader full"); |
546 |
} |
} |
547 |
|
|