/[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 561 by dpavlin, Sat Jul 1 10:19:39 2006 UTC revision 562 by dpavlin, Sun Jul 2 16:14:41 2006 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 89;  use Test::More tests => 99;
6  use Test::Exception;  use Test::Exception;
7  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
8  use blib;  use blib;
# Line 148  sub test_s { Line 148  sub test_s {
148          my $eval_t = $t;          my $eval_t = $t;
149          $eval_t =~ s/[\n\r\s]+/ /gs;          $eval_t =~ s/[\n\r\s]+/ /gs;
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;
152    
153          eval "$t";          my $v = eval "$t";
154          ok(! $@, $@ ? dump_error($@, $t) : "eval: $eval_t");          ok(! $@, $@ ? dump_error($@, $t) : "eval: $eval_t");
155            $v;
156  }  }
157    
158  {  {
# Line 397  sub test_s { Line 399  sub test_s {
399                          test_s($r) if ($r);                          test_s($r) if ($r);
400                  }                  }
401    
402                  ok(@marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");                  ok(my @marc = WebPAC::Normalize::_get_marc_fields(), "_get_marc_fields");
403                  diag dump( \@marc ) if ($debug);                  diag dump( \@marc ) if ($debug);
404                    diag "expects:\n", dump($struct) if ($debug > 1);
405                  is_deeply( \@marc, $struct, $msg );                  is_deeply( \@marc, $struct, $msg );
406          }          }
407    
# Line 459  sub test_s { Line 461  sub test_s {
461                          [ '900', 1, 0, 'c', '200c-3' ],                          [ '900', 1, 0, 'c', '200c-3' ],
462                  ],                  ],
463          );          );
464    
465            test_rec_rules(
466                    'marc_compose',
467                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
468                    qq{
469                            marc_compose('900',
470                                    'c', rec(200,'b'),
471                                    'b', rec(200,'a'),
472                                    'a', rec(200,'c'),
473                            );
474                    },
475                    [
476                            [ '900', ' ', ' ', 'c', 42, 'b', 'foo ; bar', 'a', 'baz' ]
477                    ],
478            );
479    
480            #
481            # test rules
482            #
483            sub test_rule {
484                    my ($msg, $rec, $rule, $struct) = @_;
485                    _clean_ds();
486                    _set_rec( $rec );
487                    $rule =~ s/\\/\\/gs;
488                    my $r = test_s( $rule );
489                    diag "for ", dump($rec), " got:\n", dump($r), "\nexpect:\n" if ($debug > 1);
490                    diag dump($struct) if ($debug);
491                    is_deeply( $r, $struct, $msg );
492            }
493    
494            # test split_rec_on
495            test_rule(
496                    'split_rec_on',
497                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
498                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 1) },
499                    'foo',
500            );
501            test_rule(
502                    'split_rec_on',
503                    { '200' => [{ a => 'foo ; bar', b => 42, c => 'baz' }] },
504                    qq{ split_rec_on('200','a', qr/\\s*;\\s*/, 2) },
505                    'bar',
506            );
507    
508            test_rec_rules(
509                    'marc_compose+split_rec_on',
510                    { '200' => [{ a => 'foo ! bar', b => 42, c => 'baz' }] },
511                    qq{
512                            marc_compose('900',
513                                    'a', split_rec_on(200,'a', qr/\\s*!\\s*/, 1),
514                                    'c', rec(200,'c'),
515                                    'a', split_rec_on(200,'a', qr/\\s*!\\s*/, 2),
516                                    'b', rec(200,'b'),
517                            );
518                    },
519                    [
520                            [ '900', ' ', ' ',
521                                    'a', 'foo',
522                                    'c', 'baz',
523                                    'a', 'bar',
524                                    'b', 42,
525                            ]
526                    ],
527            );
528  }  }
529    

Legend:
Removed from v.561  
changed lines
  Added in v.562

  ViewVC Help
Powered by ViewVC 1.1.26