/[webpac2]/trunk/t/3-normalize.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/3-normalize.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 538 by dpavlin, Thu Jun 29 15:29:19 2006 UTC revision 912 by dpavlin, Tue Oct 30 17:40:13 2007 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 67;  use Test::More tests => 341;
6  use Test::Exception;  use Test::Exception;
7  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
8  use blib;  use blib;
9  use File::Slurp;  use File::Slurp;
10    use Getopt::Long;
 use Data::Dumper;  
 my $debug = shift @ARGV;  
11    
12  BEGIN {  BEGIN {
13          use_ok( 'WebPAC::Normalize' );          use_ok( 'WebPAC::Normalize' );
14  }  }
15    
16    use Data::Dump qw/dump/;
17    
18    my $debug = 0;
19    GetOptions(
20            "debug+", \$debug
21    );
22    
23    cmp_ok(_debug(1), '==', 1, '_debug level');
24    cmp_ok(_debug(0), '==', 0, '_debug level');
25    
26    diag "debug level for $0 is $debug" if ($debug);
27    if ($debug > 2) {
28            diag "debug level for WebPAC::Normalize is ", _debug( $debug - 2 );
29    }
30    
31  ok(my $abs_path = abs_path($0), "abs_path");  ok(my $abs_path = abs_path($0), "abs_path");
32  $abs_path =~ s#/[^/]*$#/#;  $abs_path =~ s#/[^/]*$#/#;
33  diag "abs_path: $abs_path" if ($debug);  diag "abs_path: $abs_path" if ($debug);
34    
 #throws_ok { new WebPAC::Normalize::XML( lookup_regex => 'foo' ) } qr/pair/, "lookup_regex without lookup";  
   
35  my $rec1 = {  my $rec1 = {
36          '200' => [{          '200' => [{
37                  'a' => '200a',                  'a' => '200a',
# Line 96  my $rec2 = { Line 107  my $rec2 = {
107  };  };
108    
109    
110  my $lookup1 = {  my $lookup_hash1 = {
111          '00900' => [          'db1' => {
112                  'lookup 1',                  'input1' => {
113                  'lookup 2',                          'key1' => { 1 => 1 },
114          ],                          'key2' => { 2 => 1 },
115                    },
116                    'input2' => {
117                            'key3' => { 3 => 1 },
118                            'key4' => { 4 => 1 },
119                    },
120            },
121            'db2' => {
122                    'input3' => {
123                            'key5' => { 5 => 1 },
124                            'key6' => { 6 => 1 },
125                    },
126            }
127  };  };
128    
129  my $lookup2 = {  my $lookup_hash2 = {
130          '00900' => 'lookup',          'db3' => {
131                    'input4' => {
132                            'key7' => { 7 => 1 },
133                            'key8' => { 8 => 1 },
134                    },
135            }
136  };  };
137    
   
138  sub test {  sub test {
139          print Dumper( @_ ), ("-" x 78), "\n";          print dump( @_ ), ("-" x 78), "\n";
140          ok( defined(@_) );          ok( defined(@_) );
141  }  }
142    
# Line 135  sub test_s { Line 162  sub test_s {
162          my $eval_t = $t;          my $eval_t = $t;
163          $eval_t =~ s/[\n\r\s]+/ /gs;          $eval_t =~ s/[\n\r\s]+/ /gs;
164          $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);
165            $eval_t =~ s/\\/\\\\/gs;
166    
167          eval "$t";          my @__ret;
168          ok(! $@, $@ ? dump_error($@, $t) : "eval: $eval_t");          eval "\@__ret = $t";
169            ok(! $@, $@ ? dump_error($@, $t) : "eval: $eval_t = " . dump(@__ret));
170            return \@__ret;
171  }  }
172    
173  {  {
# Line 161  sub test_s { Line 191  sub test_s {
191    
192          # simple list manipulatons          # simple list manipulatons
193          cmp_ok( join('', prefix('ab', 'cd') ), 'eq', 'abcd', 'prefix');          cmp_ok( join('', prefix('ab', 'cd') ), 'eq', 'abcd', 'prefix');
194            cmp_ok( join('-', prefix('', 'x', 'y') ), 'eq', 'x-y', 'prefix empty');
195            cmp_ok( join('-', prefix(0, 'x', 'y') ), 'eq', '0x-0y', 'prefix 0');
196    
197          cmp_ok( join('', suffix('xy', 'cd') ), 'eq', 'cdxy', 'suffix');          cmp_ok( join('', suffix('xy', 'cd') ), 'eq', 'cdxy', 'suffix');
198            cmp_ok( join('-', suffix('', 'x', 'y' ) ), 'eq', 'x-y', 'suffix empty');
199            cmp_ok( join('-', suffix(0, 'x', 'y' ) ), 'eq', 'x0-y0', 'suffix 0');
200    
201          cmp_ok( join('', surround('->', '<-', 'a','b','c') ), 'eq', '->a<-->b<-->c<-', 'surround');          cmp_ok( join('', surround('->', '<-', 'a','b','c') ), 'eq', '->a<-->b<-->c<-', 'surround');
202            cmp_ok( join('-', surround('', '', 'x','y','z') ), 'eq', 'x-y-z', 'surround empty');
203            cmp_ok( join('-', surround(0, 0, 'x','y','z') ), 'eq', '0x0-0y0-0z0', 'surround 0 0');
204    
205            # count
206            my @el;
207            for my $i ( 0 .. 10 ) {
208                    cmp_ok( count( @el ), '==', $i, "count($i)");
209                    push @el, "element $i";
210            }
211    
212            # lookups
213    
214            throws_ok { _set_load_row() } qr/CODE/, 'empty _set_load_row()';
215    
216            ok(_set_load_row(sub {
217                    my ($database,$input,$mfn) = @_;
218                    diag "load_row( $database, $input, $mfn )" if ($debug);
219                    cmp_ok( $#_, '==', 2, 'have 3 arguments');
220                    ok($database, '_load_row database');
221                    ok($input, '_load_row input');
222                    ok($mfn, '_load_row mfn');
223                    return {
224                            '900' => [{ x => '900x-' . $mfn , y => '900y-' . $mfn }],
225                    }
226    
227            }), '_set_load_row');
228    
229            my @v = qw/foo bar baz aaa bbb ccc ddd/;
230    
231            my @accumulated;
232    
233            for my $i ( 0 .. $#v ) {
234    
235                    my $mfn = 1000 + $i;
236    
237                    ok(WebPAC::Normalize::_set_config({ '_mfn' => $mfn }), "_set_config _mfn=$mfn");
238    
239                    my $size = $#v + 1;
240    
241                    cmp_ok(
242                            save_into_lookup('db','input','key', sub { @v }),
243                            '==', $size, "save_into_lookup $size values"
244                    );
245    
246                    ok(my $l = WebPAC::Normalize::_get_lookup(), '_get_lookup');
247                    diag "_get_lookup = ", dump($l) if ($debug);
248    
249                    my @lookup;
250    
251                    ok(@lookup = lookup(
252                                    sub {
253                                            diag "in show" if ($debug);
254                                            rec('900','x');
255                                    },
256                                    'db','input','key',
257                                    sub {
258                                            return @v;
259                                    }
260                            ),
261                    "lookup db/input/key");
262    
263                    push @accumulated, '900x-' . $mfn;
264    
265                    is_deeply(\@lookup, \@accumulated, "lookup db/input/key");
266    
267                    shift @v;
268    
269            }
270    
271            ok(my $l = WebPAC::Normalize::_get_lookup(), '_get_lookup');
272            diag "_get_lookup = ", dump($l) if ($debug);
273    
274            is_deeply( $l, {
275                    db => {
276                            input => {
277                                    key => {
278                                            foo => { 1000 => 1 },
279                                            bar => { 1000 => 1, 1001 => 1 },
280                                            baz => { 1000 => 1, 1001 => 1, 1002 => 1 },
281                                            aaa => { 1000 => 1, 1001 => 1, 1002 => 1, 1003 => 1 },
282                                            bbb => { 1000 => 1, 1001 => 1, 1002 => 1, 1003 => 1, 1004 => 1 },
283                                            ccc => { 1000 => 1, 1001 => 1, 1002 => 1, 1003 => 1, 1004 => 1, 1005 => 1 },
284                                            ddd => { 1000 => 1, 1001 => 1, 1002 => 1, 1003 => 1, 1004 => 1, 1005 => 1, 1006 => 1 },
285                                    },
286                            },
287                    },
288            }, 'lookup data');
289    
290    #######
291    
292            diag "lookup_hash1 = ", dump($lookup_hash1) if ($debug);
293            ok(_set_lookup( $lookup_hash1 ), '_set_lookup $lookup_hash1');
294    
295            throws_ok { _set_load_row() } qr/CODE/, 'empty _set_load_row()';
296    
297            ok(_set_load_row(sub {
298                    my ($database,$input,$mfn) = @_;
299                    diag "load_row( $database, $input, $mfn )";
300                    cmp_ok( $#_, '==', 2, 'have 3 arguments');
301                    ok($database, 'database');
302                    ok($input, 'input');
303                    ok($mfn, 'mfn');
304    
305            }), '_set_load_row');
306    
307    
308    #       cmp_ok(lookup(
309    #               sub {
310    #                       'found'
311    #               },
312    #               'db1','input1','key1',
313    #               sub {
314    #                       rec('200','a')
315    #               }
316    #       ), 'eq', 'found', 'lookup db1/input1/key1');
317    
318    
         _set_lookup( $lookup1 );  
319                    
320          cmp_ok(  #       cmp_ok(
321                  join_with(" i ",  #               lookup(
322                          lookup(  #               ),
323                                  regex( 's/^/00/',  #       'eq', 'lookup 1 i lookup 2', 'join lookup regex rec2');
                                         rec2('902','z')  
                                 )  
                         )  
                 ),  
         'eq', 'lookup 1 i lookup 2', 'join lookup regex rec2');  
324    
325          # check join_with operations          # check join_with operations
326    
# Line 219  sub test_s { Line 364  sub test_s {
364    
365          # test lookups          # test lookups
366    
367          _set_lookup( $lookup2 );          _set_lookup( $lookup_hash2 );
368    
369          is_deeply( \[ lookup( prefix( '00', rec('902') ) ) ], \[ 'lookup' ], 'lookup prefix' );          throws_ok { lookup() } qr/need/, 'empty lookup';
370    
371          ok(! lookup('non-existent'), 'lookup non-existant' );          #is_deeply( \[ lookup( prefix( '00', rec('902') ) ) ], \[ 'lookup' ], 'lookup prefix' );
372    
373            #ok(! lookup('non-existent'), 'lookup non-existant' );
374    
375          _set_rec( $rec2 );          _set_rec( $rec2 );
376    
377          test_s(qq{          test_s(qq{
378                  tag('Title',                  search_display('Title',
379                          rec('200','a')                          rec('200','a')
380                  );                  );
381          });          });
382          test_s(qq{          test_s(qq{
383                  tag('Who',                  search_display('Who',
384                          join_with(" ",                          join_with(" ",
385                                  rec('702','a'),                                  rec('702','a'),
386                                  rec('702','b')                                  rec('702','b')
# Line 256  sub test_s { Line 403  sub test_s {
403          });          });
404    
405          ok(my $ds = _get_ds(), "get_ds");          ok(my $ds = _get_ds(), "get_ds");
406          diag "ds = ", Dumper($ds) if ($debug);          diag "ds = ", dump($ds) if ($debug);
407    
408    
409          sub test_check_ds {          sub test_check_ds {
# Line 264  sub test_s { Line 411  sub test_s {
411                  my $t = shift;                  my $t = shift;
412    
413                  ok($ds = _get_ds(), 'get_ds');                  ok($ds = _get_ds(), 'get_ds');
414                  diag Dumper( $ds ) if ($debug);                  diag dump( $ds ) if ($debug);
415    
416                  ok( $ds && $ds->{something}, 'get_ds->something exists' );                  ok( $ds && $ds->{something}, 'get_ds->something exists' );
417                  ok( $ds && $ds->{something}->{$t}, 'get_ds->something->'.$t.' exists') if ($t);                  ok( $ds && $ds->{something}->{$t}, 'get_ds->something->'.$t.' exists') if ($t);
# Line 284  sub test_s { Line 431  sub test_s {
431          test_check_ds('display');          test_check_ds('display');
432    
433          _clean_ds();          _clean_ds();
434          test_s(qq{ tag('something', '42'); });          test_s(qq{ search_display('something', '42'); });
435          test_s(qq{ tag('empty', ''); });          test_s(qq{ search_display('empty', ''); });
436          test_check_ds('search');          test_check_ds('search');
437          test_check_ds('display');          test_check_ds('display');
438    
# Line 296  sub test_s { Line 443  sub test_s {
443          test_s( $n );          test_s( $n );
444    
445          ok($ds = _get_ds(), "get_ds");          ok($ds = _get_ds(), "get_ds");
446          diag "ds = ", Dumper($ds) if ($debug);          diag "ds = ", dump($ds) if ($debug);
447    
448          my $rec = {          my $rec = {
449                  '200' => [{                  '200' => [{
# Line 313  sub test_s { Line 460  sub test_s {
460          is_deeply( $ds, {          is_deeply( $ds, {
461                  'mixed' => {                  'mixed' => {
462                          'search' => [ '200a', '200b' ],                          'search' => [ '200a', '200b' ],
                         'tag' => 'mixed'  
463                  }                  }
464          }, 'correct get_ds');          }, 'correct get_ds');
465    
# Line 337  sub test_s { Line 483  sub test_s {
483          is_deeply( $ds, {          is_deeply( $ds, {
484                  'mixed' => {                  'mixed' => {
485                          'search' => [ '200a', '200-solo' ],                          'search' => [ '200a', '200-solo' ],
                         'tag' => 'mixed'  
486                  }                  }
487          }, 'correct get_ds');          }, 'correct get_ds');
488    
489            #
490            # MARC
491            #
492            #_debug( 4 );
493    
494            test_s(qq{ marc_indicators('900',1,2) });
495            test_s(qq{ marc('900','a', rec('200') ) });
496            my $marc;
497            ok($marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
498            diag dump( $marc ) if ($debug);
499    
500            is_deeply( $marc, [
501                    [ '900', 1, 2, 'a', '200a' ],
502                    [ '900', 1, 2, 'a', '200-solo' ]
503            ], 'correct marc with indicators');
504    
505            test_s(qq{ marc_indicators('900',' ',9) });
506            test_s(qq{ marc_repeatable_subfield('900','a', rec('200') ) });
507    
508            ok($marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
509            diag dump( $marc ) if ($debug);
510    
511            is_deeply( $marc, [
512                    [ '900', 1, 2, 'a', '200a', 'a', '200-solo' ],
513                    [ '900', ' ', 9, 'a', '200a', 'a', '200-solo' ]
514            ], 'correct marc with repetable subfield');
515    
516            #
517            # test magic re-ordering of input data
518            #
519    
520            sub test_rec_rules {
521                    my ($msg, $rec, $rules, $struct) = @_;
522    
523                    _clean_ds();
524                    _set_rec($rec);
525    
526                    foreach my $r (split(/;/, $rules)) {
527                            $r =~ s/[\s\n\r]+/ /gs;
528                            $r =~ s/^\s+//gs;
529                            $r =~ s/\s+$//gs;
530                            test_s($r) if ($r);
531                    }
532    
533                    ok(my $marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
534                    diag dump( $marc ) if ($debug);
535                    diag "expects:\n", dump($struct) if ($debug > 1);
536                    is_deeply( $marc, $struct, $msg );
537            }
538    
539            test_rec_rules(
540                    'correct marc with repetable subfield',
541                    {
542                            '200' => [{
543                                    'a' => '200a-1',
544                                    'b' => '200b-1',
545                                    'c' => '200c-1',
546                            }, {
547                                    'a' => '200a-2',
548                                    'b' => '200b-2',
549                            }, {
550                                    'a' => '200a-3',
551                            }],
552                    },
553                    qq{
554                            marc_indicators('900',1 ,0);
555                            marc('900','a', rec('200','a') );
556                            marc('900','b', rec('200','b') );
557                            marc('900','c', rec('200','c') );
558                    },
559                    [
560                            [ '900', 1, 0, 'a', '200a-1', 'b', '200b-1', 'c', '200c-1' ],
561                            [ '900', 1, 0, 'a', '200a-2', 'b', '200b-2' ],
562                            [ '900', 1, 0, 'a', '200a-3' ],
563                    ],
564            );
565    
566    
567            test_rec_rules(
568                    'marc_repeatable_subfield',
569                    {
570                            '200' => [{
571                                    'a' => '200a-1',
572                                    'b' => '200b-1',
573                                    'c' => '200c-1',
574                            }, {
575                                    'a' => '200a-2',
576                                    'b' => '200b-2',
577                                    'c' => '200c-2',
578                            }, {
579                                    'a' => '200a-3',
580                                    'c' => '200c-3',
581                            }],
582                    },
583                    qq{
584                            marc_indicators('900',1 ,0);
585                            marc_repeatable_subfield('900','a', rec('200','a') );
586                            marc('900','b', rec('200','b') );
587                            marc('900','c', rec('200','c') );
588                    },
589                    [
590                            [ '900', 1, 0, 'a', '200a-1', 'a', '200a-2', 'a', '200a-3', 'b', '200b-1', 'c', '200c-1' ],
591                            [ '900', 1, 0, 'b', '200b-2', 'c', '200c-2' ],
592                            [ '900', 1, 0, 'c', '200c-3' ],
593                    ],
594            );
595    
596            test_rec_rules(
597                    'marc_compose',
598                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
599                    qq{
600                            marc_compose('900',
601                                    'c', rec(200,'b'),
602                                    'b', rec(200,'a'),
603                                    'a', rec(200,'c'),
604                            );
605                    },
606                    [
607                            [ '900', ' ', ' ', 'c', 42, 'b', 'foo ; bar', 'a', 'baz' ]
608                    ],
609            );
610    
611            test_rec_rules(
612                    'marc_compose with + subfields',
613                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
614                    qq{
615                            marc_compose('900',
616                                    'a', rec(200,'a'),
617                                    '+', prefix(" * ", rec(200,'c')),
618                                    'b', rec(200,'b'),
619                                    '+', prefix(" : ", rec(200,'c')),
620                            );
621                    },
622                    [
623                            [ '900', ' ', ' ', 'a', 'foo ; bar * baz', 'b', '42 : baz' ]
624                    ],
625            );
626    
627            #
628            # test rules
629            #
630            sub test_rule {
631                    my ($msg, $rec, $rule, $struct) = @_;
632                    _clean_ds();
633                    _set_rec( $rec );
634                    $rule =~ s/\\/\\/gs;
635                    my $r = test_s( $rule );
636                    diag "for ", dump($rec), " got:\n", dump($r), "\nexpect:\n" if ($debug > 1);
637                    diag dump($struct) if ($debug);
638                    is_deeply( $r, $struct, $msg );
639            }
640    
641            # test split_rec_on
642            test_rule(
643                    'split_rec_on',
644                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
645                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 1) },
646                    [ 'foo' ],
647            );
648            test_rule(
649                    'split_rec_on',
650                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
651                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 2) },
652                    [ 'bar' ],
653            );
654            test_rule(
655                    'split_rec_on no part',
656                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
657                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/) },
658                    [ 'foo', 'bar' ],
659            );
660            test_rule(
661                    'split_rec_on no record',
662                    {},
663                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/) },
664                    [ '' ],
665            );
666    
667            test_rec_rules(
668                    'marc_compose+split_rec_on',
669                    { '200' => [{ a => 'foo ! bar', b => 42, c => 'baz' }] },
670                    qq{
671                            marc_compose('900',
672                                    'a', split_rec_on(200,'a', qr/\\s*!\\s*/, 1),
673                                    'c', rec(200,'c'),
674                                    'a', split_rec_on(200,'a', qr/\\s*!\\s*/, 2),
675                                    'b', rec(200,'b'),
676                            );
677                    },
678                    [
679                            [ '900', ' ', ' ',
680                                    'a', 'foo',
681                                    'c', 'baz',
682                                    'a', 'bar',
683                                    'b', 42,
684                            ]
685                    ],
686            );
687    
688            cmp_ok(marc_leader('06',42), '==', 42, 'marc_leader');
689            cmp_ok(marc_leader('11',5), '==', 5, 'marc_leader');
690            ok(marc_leader(), 'marc_leader get');
691            diag "leader: ", dump(marc_leader()) if ($debug);
692            is_deeply(marc_leader(), { '06' => 42, 11 => 5 }, "marc_leader full");
693    
694            test_rule(
695                    'rec1(000)',
696                    { '000' => [ 42 ]},
697                    qq{ rec('000') },
698                    [ 42 ],
699            );
700    
701            test_rec_rules(
702                    'marc(001,rec(000))',
703                    { '000' => [ 42 ]},
704                    qq{
705                            marc('001', rec('000') );
706                    },
707                    [
708                            [ '001', 42, ]
709                    ],
710            );
711    
712            test_rec_rules(
713                    'marc_remove subfield',
714                    { '200' => [{ a => 42, b => 'bar', c => 'baz' }] },
715                    qq{
716                            marc('900', 'a', rec('200','a') );
717                            marc('900', 'b', rec('200','b') );
718                            marc_remove('900','b');
719                            marc('900', 'b', rec('200','c') );
720                            marc_remove('900','a');
721                    },
722                    [
723                            [ '900', ' ', ' ', 'b', 'baz' ],
724                    ],
725            );
726    
727            test_rec_rules(
728                    'marc_remove field',
729                    { '200' => [{ a => 42, b => 'bar', c => 'baz' }] },
730                    qq{
731                            marc('900', 'a', rec('200','a') );
732                            marc('900', 'b', rec('200','b') );
733                            marc('901', 'b', rec('200','b') );
734                            marc('901', 'c', rec('200','c') );
735                            marc_remove('900');
736                    },
737                    [
738                            [ '901', ' ', ' ', 'b', 'bar', 'c', 'baz' ],
739                    ],
740            );
741    
742            test_s(qq{ marc_remove('*'); });
743            ok(! WebPAC::Normalize::_get_marc_fields(), 'marc_remove(*)');
744    
745            test_rec_rules(
746                    'marc_duplicate',
747                    { '200' => [{ a => 42, b => 'bar', c => 'baz', d => 'bing', e => 'bong' }] },
748                    qq{
749                            marc_leader('06',42);
750                            marc_leader('11',0);
751                            marc('900', 'a', rec('200','a') );
752                            marc('900', 'b', rec('200','b') );
753                            marc_duplicate;
754                            marc_leader('11',1);
755                            marc_remove('900','b');
756                            marc('900', 'b', rec('200','c') );
757                            marc_duplicate;
758                            marc_leader('11',2);
759                            marc_remove('900','b');
760                            marc('900', 'b', rec('200','d') );
761                            marc_duplicate;
762                            marc_leader('11',3);
763                            marc_remove('900','b');
764                            marc('900', 'b', rec('200','e') );
765                    },
766                    [
767                            # this will return FIRST record
768                            [ '900', ' ', ' ', 'a', 42, 'b', 'bar' ],
769                    ],
770            );
771    
772            cmp_ok( marc_count(), '==', 3, 'marc_count' );
773    
774            my $i = 0;
775            foreach my $v ( qw/bar baz bing bong/ ) {
776    
777                    ok($marc = WebPAC::Normalize::_get_marc_fields( offset => $i ),
778                            "_get_marc_fields( offset => $i )"
779                    );
780                    diag "marc $i = ", dump( $marc ) if ($debug);
781                    is_deeply( $marc,
782                            [ [ '900', ' ', ' ', 'a', 42, 'b', $v ] ],
783                            "MARC copy $i has $v",
784                    );
785                    is_deeply(WebPAC::Normalize::_get_marc_leader(), { '06' => 42, 11 => $i }, "_get_marc_leader copy $i");
786                    $i++;
787            }
788    
789            test_rec_rules(
790                    'marc_original_order',
791                    {
792                            '200' => [ {
793                                    a => [ 'a1', 'a2' ], b => [ 'b1', 'b2' ], c => [ 'c1', 'c2' ],
794                                    subfields => [ qw/a 0 b 0 a 1 b 1 c 0 c 1/ ],
795                            }, {
796                                    a => [ 'a3', 'a4', 'a5' ], b => 'b3', c => 'c3',
797                                    subfields => [ qw/a 0 a 1 b 0 c 0 a 2/ ],
798                            } ],
799                    },
800                    qq{
801                            marc_original_order(900,200);
802                    },
803                    [
804                            [ '900', ' ', ' ', 'a', 'a1', 'b', 'b1', 'a', 'a2', 'b', 'b2', 'c', 'c1', 'c', 'c2', ],
805                            [ '900', ' ', ' ', 'a', 'a3', 'a', 'a4', 'b', 'b3', 'c', 'c3', 'a', 'a5', ],
806                    ],
807            );
808    
809            test_rule(
810                    'rec1 skips subfields',
811                    {
812                            '200' => [ {
813                                    a => [ 'a1', 'a2' ], b => [ 'b1', 'b2' ], c => [ 'c1', 'c2' ],
814                                    subfields => [ qw/a 0 b 0 a 1 b 1 c 0 c 1/ ],
815                            }, {
816                                    a => [ 'a3', 'a4', 'a5' ], b => 'b3', c => 'c3',
817                                    subfields => [ qw/a 0 a 1 b 0 c 0 a 2/ ],
818                            } ],
819                    },
820                    qq{
821                            rec1(200);
822                    },
823                    ['a1', 'b1', 'a2', 'b2', 'c1', 'c2', 'a3', 'a4', 'b3', 'c3', 'a5' ],
824            );
825    
826            is_deeply(
827                    [ _pack_subfields_hash({
828                            a => [ 'a1', 'a2' ], b => [ 'b1', 'b2' ], c => [ 'c1', 'c2' ],
829                            subfields => [ qw/a 0 b 0 a 1 b 1 c 0 c 1/ ],
830                    }) ],
831                    ['a1', 'b1', 'a2', 'b2', 'c1', 'c2'],
832                    '_pack_subfields_hash( $h )'
833            );
834    
835            cmp_ok(
836                    _pack_subfields_hash({
837                            a => [ 'a1', 'a2' ], b => [ 'b1', 'b2' ], c => [ 'c1', 'c2' ],
838                            subfields => [ qw/a 0 b 0 a 1 b 1 c 0 c 1/ ],
839                    }, 1),
840                    'eq',
841                    '^aa1^bb1^aa2^bb2^cc1^cc2',
842                    '_pack_subfields_hash( $h, 1 )'
843            );
844    
845            _clean_ds();
846            test_s(qq{
847                    marc_fixed('008', 0, 'abcdef');
848                    marc_fixed('000', 5, '5');
849                    marc_fixed('000', 10, 'A');
850                    marc_fixed('000', 0, '0');
851            });
852            ok( my $m = WebPAC::Normalize::_get_marc_fields(), '_get_marc_fields');
853            diag dump( $m );
854            is_deeply( WebPAC::Normalize::_get_marc_fields(),
855                    [
856                            ["008", "abcdef"],
857                            #        0....5....10
858                            ["000", "0    5    A"]
859                    ]
860            );
861  }  }
862    

Legend:
Removed from v.538  
changed lines
  Added in v.912

  ViewVC Help
Powered by ViewVC 1.1.26