/[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 564 by dpavlin, Sun Jul 2 20:14:21 2006 UTC revision 603 by dpavlin, Sun Jul 23 20:19:56 2006 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 103;  use Test::More tests => 150;
6  use Test::Exception;  use Test::Exception;
7  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
8  use blib;  use blib;
# Line 150  sub test_s { Line 150  sub test_s {
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;          $eval_t =~ s/\\/\\\\/gs;
152    
153          my $v = eval "$t";          my @__ret;
154          ok(! $@, $@ ? dump_error($@, $t) : "eval: $eval_t");          eval "\@__ret = $t";
155          $v;          ok(! $@, $@ ? dump_error($@, $t) : "eval: $eval_t = " . dump(@__ret));
156            return \@__ret;
157  }  }
158    
159  {  {
# Line 359  sub test_s { Line 360  sub test_s {
360          #          #
361          # MARC          # MARC
362          #          #
363            _debug( 4 );
364    
365          test_s(qq{ marc_indicators('900',1,2) });          test_s(qq{ marc_indicators('900',1,2) });
366          test_s(qq{ marc('900','a', rec('200') ) });          test_s(qq{ marc('900','a', rec('200') ) });
367          my @marc;          my $marc;
368          ok(@marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");          ok($marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
369          diag dump( \@marc ) if ($debug);          diag dump( $marc ) if ($debug);
370    
371          is_deeply( \@marc, [          is_deeply( $marc, [
372                  [ '900', 1, 2, 'a', '200a' ],                  [ '900', 1, 2, 'a', '200a' ],
373                  [ '900', 1, 2, 'a', '200-solo' ]                  [ '900', 1, 2, 'a', '200-solo' ]
374          ], 'correct marc with indicators');          ], 'correct marc with indicators');
# Line 374  sub test_s { Line 376  sub test_s {
376          test_s(qq{ marc_indicators('900',' ',9) });          test_s(qq{ marc_indicators('900',' ',9) });
377          test_s(qq{ marc_repeatable_subfield('900','a', rec('200') ) });          test_s(qq{ marc_repeatable_subfield('900','a', rec('200') ) });
378    
379          ok(@marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");          ok($marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
380          diag dump( \@marc ) if ($debug);          diag dump( $marc ) if ($debug);
381    
382          is_deeply( \@marc, [          is_deeply( $marc, [
383                  [ '900', 1, 2, 'a', '200a', 'a', '200-solo' ],                  [ '900', 1, 2, 'a', '200a', 'a', '200-solo' ],
384                  [ '900', ' ', 9, 'a', '200a', 'a', '200-solo' ]                  [ '900', ' ', 9, 'a', '200a', 'a', '200-solo' ]
385          ], 'correct marc with repetable subfield');          ], 'correct marc with repetable subfield');
# Line 399  sub test_s { Line 401  sub test_s {
401                          test_s($r) if ($r);                          test_s($r) if ($r);
402                  }                  }
403    
404                  ok(my @marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");                  ok(my $marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
405                  diag dump( \@marc ) if ($debug);                  diag dump( $marc ) if ($debug);
406                  diag "expects:\n", dump($struct) if ($debug > 1);                  diag "expects:\n", dump($struct) if ($debug > 1);
407                  is_deeply( \@marc, $struct, $msg );                  is_deeply( $marc, $struct, $msg );
408          }          }
409    
410          test_rec_rules(          test_rec_rules(
# Line 477  sub test_s { Line 479  sub test_s {
479                  ],                  ],
480          );          );
481    
482            test_rec_rules(
483                    'marc_compose with + subfields',
484                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
485                    qq{
486                            marc_compose('900',
487                                    'a', rec(200,'a'),
488                                    '+', prefix(" * ", rec(200,'c')),
489                                    'b', rec(200,'b'),
490                                    '+', prefix(" : ", rec(200,'c')),
491                            );
492                    },
493                    [
494                            [ '900', ' ', ' ', 'a', 'foo ; bar * baz', 'b', '42 : baz' ]
495                    ],
496            );
497    
498          #          #
499          # test rules          # test rules
500          #          #
# Line 496  sub test_s { Line 514  sub test_s {
514                  'split_rec_on',                  'split_rec_on',
515                  { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },                  { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
516                  qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 1) },                  qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 1) },
517                  'foo',                  [ 'foo' ],
518          );          );
519          test_rule(          test_rule(
520                  'split_rec_on',                  'split_rec_on',
521                  { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },                  { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
522                  qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 2) },                  qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 2) },
523                  'bar',                  [ 'bar' ],
524            );
525            test_rule(
526                    'split_rec_on no part',
527                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
528                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/) },
529                    [ 'foo', 'bar' ],
530            );
531            test_rule(
532                    'split_rec_on no record',
533                    {},
534                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/) },
535                    [ '' ],
536          );          );
537    
538          test_rec_rules(          test_rec_rules(
# Line 531  sub test_s { Line 561  sub test_s {
561          ok(marc_leader(), 'marc_leader get');          ok(marc_leader(), 'marc_leader get');
562          diag "leader: ", dump(marc_leader()) if ($debug);          diag "leader: ", dump(marc_leader()) if ($debug);
563          is_deeply(marc_leader(), { '06' => 42, 11 => 5 }, "marc_leader full");          is_deeply(marc_leader(), { '06' => 42, 11 => 5 }, "marc_leader full");
564    
565            test_rule(
566                    'rec1(000)',
567                    { '000' => [ 42 ]},
568                    qq{ rec('000') },
569                    [ 42 ],
570            );
571    
572            test_rec_rules(
573                    'marc(001,rec(000))',
574                    { '000' => [ 42 ]},
575                    qq{
576                            marc('001', rec('000') );
577                    },
578                    [
579                            [ '001', 42, ]
580                    ],
581            );
582    
583            test_rec_rules(
584                    'marc_remove subfield',
585                    { '200' => [{ a => 42, b => 'bar', c => 'baz' }] },
586                    qq{
587                            marc('900', 'a', rec('200','a') );
588                            marc('900', 'b', rec('200','b') );
589                            marc_remove('900','b');
590                            marc('900', 'b', rec('200','c') );
591                            marc_remove('900','a');
592                    },
593                    [
594                            [ '900', ' ', ' ', 'b', 'baz' ],
595                    ],
596            );
597    
598            test_rec_rules(
599                    'marc_remove field',
600                    { '200' => [{ a => 42, b => 'bar', c => 'baz' }] },
601                    qq{
602                            marc('900', 'a', rec('200','a') );
603                            marc('900', 'b', rec('200','b') );
604                            marc('901', 'b', rec('200','b') );
605                            marc('901', 'c', rec('200','c') );
606                            marc_remove('900');
607                    },
608                    [
609                            [ '901', ' ', ' ', 'b', 'bar', 'c', 'baz' ],
610                    ],
611            );
612            test_rec_rules(
613                    'marc_duplicate',
614                    { '200' => [{ a => 42, b => 'bar', c => 'baz', d => 'bing', e => 'bong' }] },
615                    qq{
616                            marc('900', 'a', rec('200','a') );
617                            marc('900', 'b', rec('200','b') );
618                            marc_duplicate;
619                            marc_remove('900','b');
620                            marc('900', 'b', rec('200','c') );
621                            marc_duplicate;
622                            marc_remove('900','b');
623                            marc('900', 'b', rec('200','d') );
624                            marc_duplicate;
625                            marc_remove('900','b');
626                            marc('900', 'b', rec('200','e') );
627                    },
628                    [
629                            # this will return FIRST record
630                            [ '900', ' ', ' ', 'a', 42, 'b', 'bar' ],
631                    ],
632            );
633    
634            my $i = 0;
635            foreach my $v ( qw/bar baz bing bong/ ) {
636    
637                    ok($marc = WebPAC::Normalize::_get_marc_fields( offset => $i ),
638                            "_get_marc_fields( offset => $i )"
639                    );
640                    diag "marc $i = ", dump( $marc ) if ($debug);
641                    is_deeply( $marc,
642                            [ [ '900', ' ', ' ', 'a', 42, 'b', $v ] ],
643                            "MARC copy $i has $v",
644                    );
645                    $i++;
646            }
647  }  }
648    

Legend:
Removed from v.564  
changed lines
  Added in v.603

  ViewVC Help
Powered by ViewVC 1.1.26