/[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 555 by dpavlin, Sat Jul 1 10:19:39 2006 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 81;  use Test::More tests => 89;
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);
# Line 341  sub test_s { Line 354  sub test_s {
354                  }                  }
355          }, 'correct get_ds');          }, 'correct get_ds');
356    
357            #
358          # MARC          # MARC
359            #
360    
361          test_s(qq{ marc_indicators('900',1,2) });          test_s(qq{ marc_indicators('900',1,2) });
362          test_s(qq{ marc('900','a', rec('200') ) });          test_s(qq{ marc('900','a', rec('200') ) });
363          my @marc;          my @marc;
# Line 364  sub test_s { Line 380  sub test_s {
380                  [ '900', ' ', 9, 'a', '200a', 'a', '200-solo' ]                  [ '900', ' ', 9, 'a', '200a', 'a', '200-solo' ]
381          ], 'correct marc with repetable subfield');          ], 'correct marc with repetable subfield');
382    
383          _clean_ds();          #
384          _set_rec({          # test magic re-ordering of input data
385                  '200' => [{          #
386                          'a' => '200a-1',  
387                          'b' => '200b-1',          sub test_rec_rules {
388                          'c' => '200c-1',                  my ($msg, $rec, $rules, $struct) = @_;
389                  }, {  
390                          'a' => '200a-2',                  _clean_ds();
391                          'b' => '200b-2',                  _set_rec($rec);
392                          'c' => '200c-2',  
393                  }, {                  foreach my $r (split(/;/, $rules)) {
394                          'a' => '200a-3',                          $r =~ s/[\s\n\r]+/ /gs;
395                          'c' => '200c-3',                          $r =~ s/^\s+//gs;
396                  }]                          $r =~ s/\s+$//gs;
397          });                          test_s($r) if ($r);
398          test_s(qq{ marc_indicators('900',1 ,0) });                  }
         test_s(qq{ marc_repeatable_subfield('900','a', rec('200','a') ) });  
         test_s(qq{ marc('900','b', rec('200','b') ) });  
         test_s(qq{ marc('900','c', rec('200','c') ) });  
399    
400          ok(@marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");                  ok(@marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
401          diag dump( \@marc ) if ($debug);                  diag dump( \@marc ) if ($debug);
402    
403          is_deeply( \@marc, [                  is_deeply( \@marc, $struct, $msg );
404                  [ '900', 1, 0, 'a', '200a-1', 'a', '200a-2', 'a', '200a-3', 'b', '200b-1', 'c', '200c-1' ],          }
405                  [ '900', 1, 0, 'b', '200b-2', 'c', '200c-2' ],  
406                  [ '900', 1, 0, 'c', '200c-3' ],          test_rec_rules(
407          ], 'correct marc with repetable subfield');                  'correct marc with repetable subfield',
408                    {
409                            '200' => [{
410                                    'a' => '200a-1',
411                                    'b' => '200b-1',
412                                    'c' => '200c-1',
413                            }, {
414                                    'a' => '200a-2',
415                                    'b' => '200b-2',
416                            }, {
417                                    'a' => '200a-3',
418                            }],
419                    },
420                    qq{
421                            marc_indicators('900',1 ,0);
422                            marc('900','a', rec('200','a') );
423                            marc('900','b', rec('200','b') );
424                            marc('900','c', rec('200','c') );
425                    },
426                    [
427                            [ '900', 1, 0, 'a', '200a-1', 'b', '200b-1', 'c', '200c-1' ],
428                            [ '900', 1, 0, 'a', '200a-2', 'b', '200b-2' ],
429                            [ '900', 1, 0, 'a', '200a-3' ],
430                    ],
431            );
432    
433    
434            test_rec_rules(
435                    'marc_repeatable_subfield',
436                    {
437                            '200' => [{
438                                    'a' => '200a-1',
439                                    'b' => '200b-1',
440                                    'c' => '200c-1',
441                            }, {
442                                    'a' => '200a-2',
443                                    'b' => '200b-2',
444                                    'c' => '200c-2',
445                            }, {
446                                    'a' => '200a-3',
447                                    'c' => '200c-3',
448                            }],
449                    },
450                    qq{
451                            marc_indicators('900',1 ,0);
452                            marc_repeatable_subfield('900','a', rec('200','a') );
453                            marc('900','b', rec('200','b') );
454                            marc('900','c', rec('200','c') );
455                    },
456                    [
457                            [ '900', 1, 0, 'a', '200a-1', 'a', '200a-2', 'a', '200a-3', 'b', '200b-1', 'c', '200c-1' ],
458                            [ '900', 1, 0, 'b', '200b-2', 'c', '200c-2' ],
459                            [ '900', 1, 0, 'c', '200c-3' ],
460                    ],
461            );
462  }  }
463    

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

  ViewVC Help
Powered by ViewVC 1.1.26