/[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 550 by dpavlin, Fri Jun 30 18:48:33 2006 UTC revision 819 by dpavlin, Wed Apr 11 10:09:34 2007 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 81;  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::Dump qw/dump/;  
 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 dump( @_ ), ("-" x 78), "\n";          print dump( @_ ), ("-" x 78), "\n";
140          ok( defined(@_) );          ok( defined(@_) );
# 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    
# Line 341  sub test_s { Line 488  sub test_s {
488                  }                  }
489          }, 'correct get_ds');          }, 'correct get_ds');
490    
491            #
492          # MARC          # MARC
493            #
494            #_debug( 4 );
495    
496          test_s(qq{ marc_indicators('900',1,2) });          test_s(qq{ marc_indicators('900',1,2) });
497          test_s(qq{ marc('900','a', rec('200') ) });          test_s(qq{ marc('900','a', rec('200') ) });
498          my @marc;          my $marc;
499          ok(@marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");          ok($marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
500          diag dump( \@marc ) if ($debug);          diag dump( $marc ) if ($debug);
501    
502          is_deeply( \@marc, [          is_deeply( $marc, [
503                  [ '900', 1, 2, 'a', '200a' ],                  [ '900', 1, 2, 'a', '200a' ],
504                  [ '900', 1, 2, 'a', '200-solo' ]                  [ '900', 1, 2, 'a', '200-solo' ]
505          ], 'correct marc with indicators');          ], 'correct marc with indicators');
# Line 356  sub test_s { Line 507  sub test_s {
507          test_s(qq{ marc_indicators('900',' ',9) });          test_s(qq{ marc_indicators('900',' ',9) });
508          test_s(qq{ marc_repeatable_subfield('900','a', rec('200') ) });          test_s(qq{ marc_repeatable_subfield('900','a', rec('200') ) });
509    
510          ok(@marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");          ok($marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
511          diag dump( \@marc ) if ($debug);          diag dump( $marc ) if ($debug);
512    
513          is_deeply( \@marc, [          is_deeply( $marc, [
514                  [ '900', 1, 2, 'a', '200a', 'a', '200-solo' ],                  [ '900', 1, 2, 'a', '200a', 'a', '200-solo' ],
515                  [ '900', ' ', 9, 'a', '200a', 'a', '200-solo' ]                  [ '900', ' ', 9, 'a', '200a', 'a', '200-solo' ]
516          ], 'correct marc with repetable subfield');          ], 'correct marc with repetable subfield');
517    
518            #
519            # test magic re-ordering of input data
520            #
521    
522            sub test_rec_rules {
523                    my ($msg, $rec, $rules, $struct) = @_;
524    
525                    _clean_ds();
526                    _set_rec($rec);
527    
528                    foreach my $r (split(/;/, $rules)) {
529                            $r =~ s/[\s\n\r]+/ /gs;
530                            $r =~ s/^\s+//gs;
531                            $r =~ s/\s+$//gs;
532                            test_s($r) if ($r);
533                    }
534    
535                    ok(my $marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
536                    diag dump( $marc ) if ($debug);
537                    diag "expects:\n", dump($struct) if ($debug > 1);
538                    is_deeply( $marc, $struct, $msg );
539            }
540    
541            test_rec_rules(
542                    'correct marc with repetable subfield',
543                    {
544                            '200' => [{
545                                    'a' => '200a-1',
546                                    'b' => '200b-1',
547                                    'c' => '200c-1',
548                            }, {
549                                    'a' => '200a-2',
550                                    'b' => '200b-2',
551                            }, {
552                                    'a' => '200a-3',
553                            }],
554                    },
555                    qq{
556                            marc_indicators('900',1 ,0);
557                            marc('900','a', rec('200','a') );
558                            marc('900','b', rec('200','b') );
559                            marc('900','c', rec('200','c') );
560                    },
561                    [
562                            [ '900', 1, 0, 'a', '200a-1', 'b', '200b-1', 'c', '200c-1' ],
563                            [ '900', 1, 0, 'a', '200a-2', 'b', '200b-2' ],
564                            [ '900', 1, 0, 'a', '200a-3' ],
565                    ],
566            );
567    
568    
569            test_rec_rules(
570                    'marc_repeatable_subfield',
571                    {
572                            '200' => [{
573                                    'a' => '200a-1',
574                                    'b' => '200b-1',
575                                    'c' => '200c-1',
576                            }, {
577                                    'a' => '200a-2',
578                                    'b' => '200b-2',
579                                    'c' => '200c-2',
580                            }, {
581                                    'a' => '200a-3',
582                                    'c' => '200c-3',
583                            }],
584                    },
585                    qq{
586                            marc_indicators('900',1 ,0);
587                            marc_repeatable_subfield('900','a', rec('200','a') );
588                            marc('900','b', rec('200','b') );
589                            marc('900','c', rec('200','c') );
590                    },
591                    [
592                            [ '900', 1, 0, 'a', '200a-1', 'a', '200a-2', 'a', '200a-3', 'b', '200b-1', 'c', '200c-1' ],
593                            [ '900', 1, 0, 'b', '200b-2', 'c', '200c-2' ],
594                            [ '900', 1, 0, 'c', '200c-3' ],
595                    ],
596            );
597    
598            test_rec_rules(
599                    'marc_compose',
600                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
601                    qq{
602                            marc_compose('900',
603                                    'c', rec(200,'b'),
604                                    'b', rec(200,'a'),
605                                    'a', rec(200,'c'),
606                            );
607                    },
608                    [
609                            [ '900', ' ', ' ', 'c', 42, 'b', 'foo ; bar', 'a', 'baz' ]
610                    ],
611            );
612    
613            test_rec_rules(
614                    'marc_compose with + subfields',
615                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
616                    qq{
617                            marc_compose('900',
618                                    'a', rec(200,'a'),
619                                    '+', prefix(" * ", rec(200,'c')),
620                                    'b', rec(200,'b'),
621                                    '+', prefix(" : ", rec(200,'c')),
622                            );
623                    },
624                    [
625                            [ '900', ' ', ' ', 'a', 'foo ; bar * baz', 'b', '42 : baz' ]
626                    ],
627            );
628    
629            #
630            # test rules
631            #
632            sub test_rule {
633                    my ($msg, $rec, $rule, $struct) = @_;
634                    _clean_ds();
635                    _set_rec( $rec );
636                    $rule =~ s/\\/\\/gs;
637                    my $r = test_s( $rule );
638                    diag "for ", dump($rec), " got:\n", dump($r), "\nexpect:\n" if ($debug > 1);
639                    diag dump($struct) if ($debug);
640                    is_deeply( $r, $struct, $msg );
641            }
642    
643            # test split_rec_on
644            test_rule(
645                    'split_rec_on',
646                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
647                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 1) },
648                    [ 'foo' ],
649            );
650            test_rule(
651                    'split_rec_on',
652                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
653                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 2) },
654                    [ 'bar' ],
655            );
656            test_rule(
657                    'split_rec_on no part',
658                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
659                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/) },
660                    [ 'foo', 'bar' ],
661            );
662            test_rule(
663                    'split_rec_on no record',
664                    {},
665                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/) },
666                    [ '' ],
667            );
668    
669            test_rec_rules(
670                    'marc_compose+split_rec_on',
671                    { '200' => [{ a => 'foo ! bar', b => 42, c => 'baz' }] },
672                    qq{
673                            marc_compose('900',
674                                    'a', split_rec_on(200,'a', qr/\\s*!\\s*/, 1),
675                                    'c', rec(200,'c'),
676                                    'a', split_rec_on(200,'a', qr/\\s*!\\s*/, 2),
677                                    'b', rec(200,'b'),
678                            );
679                    },
680                    [
681                            [ '900', ' ', ' ',
682                                    'a', 'foo',
683                                    'c', 'baz',
684                                    'a', 'bar',
685                                    'b', 42,
686                            ]
687                    ],
688            );
689    
690            cmp_ok(marc_leader('06',42), '==', 42, 'marc_leader');
691            cmp_ok(marc_leader('11',5), '==', 5, 'marc_leader');
692            ok(marc_leader(), 'marc_leader get');
693            diag "leader: ", dump(marc_leader()) if ($debug);
694            is_deeply(marc_leader(), { '06' => 42, 11 => 5 }, "marc_leader full");
695    
696            test_rule(
697                    'rec1(000)',
698                    { '000' => [ 42 ]},
699                    qq{ rec('000') },
700                    [ 42 ],
701            );
702    
703            test_rec_rules(
704                    'marc(001,rec(000))',
705                    { '000' => [ 42 ]},
706                    qq{
707                            marc('001', rec('000') );
708                    },
709                    [
710                            [ '001', 42, ]
711                    ],
712            );
713    
714            test_rec_rules(
715                    'marc_remove subfield',
716                    { '200' => [{ a => 42, b => 'bar', c => 'baz' }] },
717                    qq{
718                            marc('900', 'a', rec('200','a') );
719                            marc('900', 'b', rec('200','b') );
720                            marc_remove('900','b');
721                            marc('900', 'b', rec('200','c') );
722                            marc_remove('900','a');
723                    },
724                    [
725                            [ '900', ' ', ' ', 'b', 'baz' ],
726                    ],
727            );
728    
729            test_rec_rules(
730                    'marc_remove field',
731                    { '200' => [{ a => 42, b => 'bar', c => 'baz' }] },
732                    qq{
733                            marc('900', 'a', rec('200','a') );
734                            marc('900', 'b', rec('200','b') );
735                            marc('901', 'b', rec('200','b') );
736                            marc('901', 'c', rec('200','c') );
737                            marc_remove('900');
738                    },
739                    [
740                            [ '901', ' ', ' ', 'b', 'bar', 'c', 'baz' ],
741                    ],
742            );
743    
744            test_s(qq{ marc_remove('*'); });
745            ok(! WebPAC::Normalize::_get_marc_fields(), 'marc_remove(*)');
746    
747            test_rec_rules(
748                    'marc_duplicate',
749                    { '200' => [{ a => 42, b => 'bar', c => 'baz', d => 'bing', e => 'bong' }] },
750                    qq{
751                            marc_leader('06',42);
752                            marc_leader('11',0);
753                            marc('900', 'a', rec('200','a') );
754                            marc('900', 'b', rec('200','b') );
755                            marc_duplicate;
756                            marc_leader('11',1);
757                            marc_remove('900','b');
758                            marc('900', 'b', rec('200','c') );
759                            marc_duplicate;
760                            marc_leader('11',2);
761                            marc_remove('900','b');
762                            marc('900', 'b', rec('200','d') );
763                            marc_duplicate;
764                            marc_leader('11',3);
765                            marc_remove('900','b');
766                            marc('900', 'b', rec('200','e') );
767                    },
768                    [
769                            # this will return FIRST record
770                            [ '900', ' ', ' ', 'a', 42, 'b', 'bar' ],
771                    ],
772            );
773    
774            cmp_ok( marc_count(), '==', 3, 'marc_count' );
775    
776            my $i = 0;
777            foreach my $v ( qw/bar baz bing bong/ ) {
778    
779                    ok($marc = WebPAC::Normalize::_get_marc_fields( offset => $i ),
780                            "_get_marc_fields( offset => $i )"
781                    );
782                    diag "marc $i = ", dump( $marc ) if ($debug);
783                    is_deeply( $marc,
784                            [ [ '900', ' ', ' ', 'a', 42, 'b', $v ] ],
785                            "MARC copy $i has $v",
786                    );
787                    is_deeply(WebPAC::Normalize::_get_marc_leader(), { '06' => 42, 11 => $i }, "_get_marc_leader copy $i");
788                    $i++;
789            }
790    
791            test_rec_rules(
792                    'marc_original_order',
793                    {
794                            '200' => [ {
795                                    a => [ 'a1', 'a2' ], b => [ 'b1', 'b2' ], c => [ 'c1', 'c2' ],
796                                    subfields => [ qw/a 0 b 0 a 1 b 1 c 0 c 1/ ],
797                            }, {
798                                    a => [ 'a3', 'a4', 'a5' ], b => 'b3', c => 'c3',
799                                    subfields => [ qw/a 0 a 1 b 0 c 0 a 2/ ],
800                            } ],
801                    },
802                    qq{
803                            marc_original_order(900,200);
804                    },
805                    [
806                            [ '900', ' ', ' ', 'a', 'a1', 'b', 'b1', 'a', 'a2', 'b', 'b2', 'c', 'c1', 'c', 'c2', ],
807                            [ '900', ' ', ' ', 'a', 'a3', 'a', 'a4', 'b', 'b3', 'c', 'c3', 'a', 'a5', ],
808                    ],
809            );
810    
811            test_rule(
812                    'rec1 skips subfields',
813                    {
814                            '200' => [ {
815                                    a => [ 'a1', 'a2' ], b => [ 'b1', 'b2' ], c => [ 'c1', 'c2' ],
816                                    subfields => [ qw/a 0 b 0 a 1 b 1 c 0 c 1/ ],
817                            }, {
818                                    a => [ 'a3', 'a4', 'a5' ], b => 'b3', c => 'c3',
819                                    subfields => [ qw/a 0 a 1 b 0 c 0 a 2/ ],
820                            } ],
821                    },
822                    qq{
823                            rec1(200);
824                    },
825                    ['a1', 'b1', 'a2', 'b2', 'c1', 'c2', 'a3', 'a4', 'b3', 'c3', 'a5' ],
826            );
827    
828            is_deeply(
829                    [ _pack_subfields_hash({
830                            a => [ 'a1', 'a2' ], b => [ 'b1', 'b2' ], c => [ 'c1', 'c2' ],
831                            subfields => [ qw/a 0 b 0 a 1 b 1 c 0 c 1/ ],
832                    }) ],
833                    ['a1', 'b1', 'a2', 'b2', 'c1', 'c2'],
834                    '_pack_subfields_hash( $h )'
835            );
836    
837            cmp_ok(
838                    _pack_subfields_hash({
839                            a => [ 'a1', 'a2' ], b => [ 'b1', 'b2' ], c => [ 'c1', 'c2' ],
840                            subfields => [ qw/a 0 b 0 a 1 b 1 c 0 c 1/ ],
841                    }, 1),
842                    'eq',
843                    '^aa1^bb1^aa2^bb2^cc1^cc2',
844                    '_pack_subfields_hash( $h, 1 )'
845            );
846    
847          _clean_ds();          _clean_ds();
848          _set_rec({          test_s(qq{
849                  '200' => [{                  marc_fixed('008', 0, 'abcdef');
850                          'a' => '200a-1',                  marc_fixed('000', 5, '5');
851                          'b' => '200b-1',                  marc_fixed('000', 10, 'A');
852                          'c' => '200c-1',                  marc_fixed('000', 0, '0');
                 }, {  
                         'a' => '200a-2',  
                         'b' => '200b-2',  
                         'c' => '200c-2',  
                 }, {  
                         'a' => '200a-3',  
                         'c' => '200c-3',  
                 }]  
853          });          });
854          test_s(qq{ marc_indicators('900',1 ,0) });          ok( my $m = WebPAC::Normalize::_get_marc_fields(), '_get_marc_fields');
855          test_s(qq{ marc_repeatable_subfield('900','a', rec('200','a') ) });          diag dump( $m );
856          test_s(qq{ marc('900','b', rec('200','b') ) });          is_deeply( WebPAC::Normalize::_get_marc_fields(),
857          test_s(qq{ marc('900','c', rec('200','c') ) });                  [
858                            ["008", "abcdef"],
859          ok(@marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");                          #        0....5....10
860          diag dump( \@marc ) if ($debug);                          ["000", "0    5    A"]
861                    ]
862          is_deeply( \@marc, [          );
                 [ '900', 1, 0, 'a', '200a-1', 'a', '200a-2', 'a', '200a-3', 'b', '200b-1', 'c', '200c-1' ],  
                 [ '900', 1, 0, 'b', '200b-2', 'c', '200c-2' ],  
                 [ '900', 1, 0, 'c', '200c-3' ],  
         ], 'correct marc with repetable subfield');  
863  }  }
864    

Legend:
Removed from v.550  
changed lines
  Added in v.819

  ViewVC Help
Powered by ViewVC 1.1.26