--- trunk/t/3-normalize.t 2006/07/03 14:30:22 571 +++ trunk/t/3-normalize.t 2006/07/03 21:08:07 574 @@ -2,7 +2,7 @@ use strict; -use Test::More tests => 112; +use Test::More tests => 140; use Test::Exception; use Cwd qw/abs_path/; use blib; @@ -360,6 +360,7 @@ # # MARC # + _debug( 4 ); test_s(qq{ marc_indicators('900',1,2) }); test_s(qq{ marc('900','a', rec('200') ) }); @@ -545,7 +546,6 @@ diag "leader: ", dump(marc_leader()) if ($debug); is_deeply(marc_leader(), { '06' => 42, 11 => 5 }, "marc_leader full"); - _debug(2); test_rule( 'rec1(000)', { '000' => [ 42 ]}, @@ -554,14 +554,65 @@ ); test_rec_rules( - 'marc_compose+split_rec_on', + 'marc(001,rec(000))', { '000' => [ 42 ]}, qq{ marc('001', rec('000') ); }, [ - [ '001', ' ', ' ', 42, ] + [ '001', 42, ] + ], + ); + + test_rec_rules( + 'marc_remove', + { '200' => [{ a => 42, b => 'bar', c => 'baz' }] }, + qq{ + marc('900', 'a', rec('200','a') ); + marc('900', 'b', rec('200','b') ); + marc_remove('900','b'); + marc('900', 'b', rec('200','c') ); + marc_remove('900','a'); + }, + [ + [ '900', ' ', ' ', 'b', 'baz' ], + ], + ); + + test_rec_rules( + 'marc_duplicate', + { '200' => [{ a => 42, b => 'bar', c => 'baz', d => 'bing', e => 'bong' }] }, + qq{ + marc('900', 'a', rec('200','a') ); + marc('900', 'b', rec('200','b') ); + marc_duplicate; + marc_remove('900','b'); + marc('900', 'b', rec('200','c') ); + marc_duplicate; + marc_remove('900','b'); + marc('900', 'b', rec('200','d') ); + marc_duplicate; + marc_remove('900','b'); + marc('900', 'b', rec('200','e') ); + }, + [ + # this will return FIRST record + [ '900', ' ', ' ', 'a', 42, 'b', 'bar' ], ], ); + + my $i = 0; + foreach my $v ( qw/bar baz bing bong/ ) { + + ok(@marc = WebPAC::Normalize::_get_marc_fields( offset => $i ), + "_get_marc_fields( offset => $i )" + ); + diag "marc $i = ", dump( @marc ) if ($debug); + is_deeply( \@marc, + [ [ '900', ' ', ' ', 'a', 42, 'b', $v ] ], + "MARC copy $i has $v", + ); + $i++; + } }