r1604@llin: dpavlin | 2007-11-11 21:02:22 +0100
[webpac2] / t / 3-normalize.t
index 3c96d97..1327252 100755 (executable)
@@ -3,7 +3,7 @@
 use strict;
 use blib;
 
-use Test::More tests => 351;
+use Test::More tests => 340;
 
 BEGIN {
        use_ok( 'WebPAC::Test' );
@@ -514,15 +514,16 @@ sub test_s {
                _clean_ds();
                _set_ds($rec);
 
-               foreach my $r (split(/;/, $rules)) {
+               foreach my $r (split(/;\s*$/, $rules)) {
                        $r =~ s/[\s\n\r]+/ /gs;
                        $r =~ s/^\s+//gs;
                        $r =~ s/\s+$//gs;
+                       diag "rule: $r" if $debug;
                        test_s($r) if ($r);
                }
 
                ok(my $marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
-               diag dump( $marc ) if ($debug);
+               diag dump( $marc ) if $debug;
                diag "expects:\n", dump($struct) if ($debug > 1);
                is_deeply( $marc, $struct, $msg );
        }
@@ -863,5 +864,33 @@ sub test_s {
                [ '1-55860-701-3', '1-55860-701-3' ],
        'isbn_10' );
 
+       # frec
+
+       my $rec = {
+                       '200' => [ {
+                               a => [ 'a1', 'a2' ], b => [ 'b1', 'b2' ], c => [ 'c1', 'c2' ],
+                               subfields => [ qw/a 0 b 0 a 1 b 1 c 0 c 1/ ],
+                       }, {
+                               a => [ 'a3', 'a4', 'a5' ], b => 'b3', c => 'c3',
+                               subfields => [ qw/a 0 a 1 b 0 c 0 a 2/ ],
+                       } ],
+       };
+
+       test_rule( 'frec', $rec, qq{ frec(200) }, [ 'a1' ] );
+       test_rule( 'frec', $rec, qq{ frec(200,'a') }, [ 'a1' ] );
+       test_rule( 'frec', $rec, qq{ frec(200,'b') }, [ 'b1' ] );
+       test_rule( 'frec', $rec, qq{ frec(200,'c') }, [ 'c1' ] );
+
+       $rec->{'900'} = $rec->{'200'};
+       foreach my $sf ( qw/a b c/ ) {
+               ok( frec_eq( '200' => $sf, '900' => $sf ), "frec_eq 200 == 900 $sf");
+               ok( ! frec_ne( '200' => $sf, '900' => $sf ), "! frec_ne 200 == 900 $sf");
+       }
+
+       foreach my $sf ( qw/a b/ ) {
+               ok( ! frec_eq( '200' => $sf, '200' => 'c' ), "! frec_eq 200 $sf == 200 c");
+               ok( frec_ne( '200' => $sf, '200' => 'c' ), "frec_ne 200 $sf == 200 c");
+       }
+
 }