/[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 725 by dpavlin, Fri Sep 29 18:55:41 2006 UTC revision 912 by dpavlin, Tue Oct 30 17:40:13 2007 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 309;  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;
# Line 191  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          # lookups
213    
214          throws_ok { _set_load_ds() } qr/CODE/, 'empty _set_load_ds()';          throws_ok { _set_load_row() } qr/CODE/, 'empty _set_load_row()';
215    
216          ok(_set_load_ds(sub {          ok(_set_load_row(sub {
217                  my ($database,$input,$mfn) = @_;                  my ($database,$input,$mfn) = @_;
218                  diag "load_ds( $database, $input, $mfn )";                  diag "load_row( $database, $input, $mfn )" if ($debug);
219                  cmp_ok( $#_, '==', 2, 'have 3 arguments');                  cmp_ok( $#_, '==', 2, 'have 3 arguments');
220                  ok($database, '_load_ds database');                  ok($database, '_load_row database');
221                  ok($input, '_load_ds input');                  ok($input, '_load_row input');
222                  ok($mfn, '_load_ds mfn');                  ok($mfn, '_load_row mfn');
223                  return {                  return {
224                          '900' => [{ x => '900x-' . $mfn , y => '900y-' . $mfn }],                          '900' => [{ x => '900x-' . $mfn , y => '900y-' . $mfn }],
225                  }                  }
226    
227          }), '_set_load_ds');          }), '_set_load_row');
228    
229          my @v = qw/foo bar baz aaa bbb ccc ddd/;          my @v = qw/foo bar baz aaa bbb ccc ddd/;
230    
# Line 229  sub test_s { Line 244  sub test_s {
244                  );                  );
245    
246                  ok(my $l = WebPAC::Normalize::_get_lookup(), '_get_lookup');                  ok(my $l = WebPAC::Normalize::_get_lookup(), '_get_lookup');
247                  diag "_get_lookup = ", dump($l);                  diag "_get_lookup = ", dump($l) if ($debug);
248    
249                  my @lookup;                  my @lookup;
250    
251                  ok(my @lookup = lookup(                  ok(@lookup = lookup(
252                                  sub {                                  sub {
253                                          diag "in show";                                          diag "in show" if ($debug);
254                                          rec('900','x');                                          rec('900','x');
255                                  },                                  },
256                                  'db','input','key',                                  'db','input','key',
# Line 254  sub test_s { Line 269  sub test_s {
269          }          }
270    
271          ok(my $l = WebPAC::Normalize::_get_lookup(), '_get_lookup');          ok(my $l = WebPAC::Normalize::_get_lookup(), '_get_lookup');
272          diag "_get_lookup = ", dump($l);          diag "_get_lookup = ", dump($l) if ($debug);
273    
274          is_deeply( $l, {          is_deeply( $l, {
275                  db => {                  db => {
# Line 274  sub test_s { Line 289  sub test_s {
289    
290  #######  #######
291    
292          diag "lookup_hash1 = ", dump($lookup_hash1);          diag "lookup_hash1 = ", dump($lookup_hash1) if ($debug);
293          ok(_set_lookup( $lookup_hash1 ), '_set_lookup $lookup_hash1');          ok(_set_lookup( $lookup_hash1 ), '_set_lookup $lookup_hash1');
294    
295          throws_ok { _set_load_ds() } qr/CODE/, 'empty _set_load_ds()';          throws_ok { _set_load_row() } qr/CODE/, 'empty _set_load_row()';
296    
297          ok(_set_load_ds(sub {          ok(_set_load_row(sub {
298                  my ($database,$input,$mfn) = @_;                  my ($database,$input,$mfn) = @_;
299                  diag "load_ds( $database, $input, $mfn )";                  diag "load_row( $database, $input, $mfn )";
300                  cmp_ok( $#_, '==', 2, 'have 3 arguments');                  cmp_ok( $#_, '==', 2, 'have 3 arguments');
301                  ok($database, 'database');                  ok($database, 'database');
302                  ok($input, 'input');                  ok($input, 'input');
303                  ok($mfn, 'mfn');                  ok($mfn, 'mfn');
304    
305          }), '_set_load_ds');          }), '_set_load_row');
306    
307    
308  #       cmp_ok(lookup(  #       cmp_ok(lookup(
# Line 360  sub test_s { Line 375  sub test_s {
375          _set_rec( $rec2 );          _set_rec( $rec2 );
376    
377          test_s(qq{          test_s(qq{
378                  tag('Title',                  search_display('Title',
379                          rec('200','a')                          rec('200','a')
380                  );                  );
381          });          });
382          test_s(qq{          test_s(qq{
383                  tag('Who',                  search_display('Who',
384                          join_with(" ",                          join_with(" ",
385                                  rec('702','a'),                                  rec('702','a'),
386                                  rec('702','b')                                  rec('702','b')
# Line 416  sub test_s { Line 431  sub test_s {
431          test_check_ds('display');          test_check_ds('display');
432    
433          _clean_ds();          _clean_ds();
434          test_s(qq{ tag('something', '42'); });          test_s(qq{ search_display('something', '42'); });
435          test_s(qq{ tag('empty', ''); });          test_s(qq{ search_display('empty', ''); });
436          test_check_ds('search');          test_check_ds('search');
437          test_check_ds('display');          test_check_ds('display');
438    
# Line 445  sub test_s { Line 460  sub test_s {
460          is_deeply( $ds, {          is_deeply( $ds, {
461                  'mixed' => {                  'mixed' => {
462                          'search' => [ '200a', '200b' ],                          'search' => [ '200a', '200b' ],
                         'tag' => 'mixed'  
463                  }                  }
464          }, 'correct get_ds');          }, 'correct get_ds');
465    
# Line 469  sub test_s { Line 483  sub test_s {
483          is_deeply( $ds, {          is_deeply( $ds, {
484                  'mixed' => {                  'mixed' => {
485                          'search' => [ '200a', '200-solo' ],                          'search' => [ '200a', '200-solo' ],
                         'tag' => 'mixed'  
486                  }                  }
487          }, 'correct get_ds');          }, 'correct get_ds');
488    
# Line 725  sub test_s { Line 738  sub test_s {
738                          [ '901', ' ', ' ', 'b', 'bar', 'c', 'baz' ],                          [ '901', ' ', ' ', 'b', 'bar', 'c', 'baz' ],
739                  ],                  ],
740          );          );
741    
742            test_s(qq{ marc_remove('*'); });
743            ok(! WebPAC::Normalize::_get_marc_fields(), 'marc_remove(*)');
744    
745          test_rec_rules(          test_rec_rules(
746                  'marc_duplicate',                  'marc_duplicate',
747                  { '200' => [{ a => 42, b => 'bar', c => 'baz', d => 'bing', e => 'bong' }] },                  { '200' => [{ a => 42, b => 'bar', c => 'baz', d => 'bing', e => 'bong' }] },
748                  qq{                  qq{
749                            marc_leader('06',42);
750                            marc_leader('11',0);
751                          marc('900', 'a', rec('200','a') );                          marc('900', 'a', rec('200','a') );
752                          marc('900', 'b', rec('200','b') );                          marc('900', 'b', rec('200','b') );
753                          marc_duplicate;                          marc_duplicate;
754                            marc_leader('11',1);
755                          marc_remove('900','b');                          marc_remove('900','b');
756                          marc('900', 'b', rec('200','c') );                          marc('900', 'b', rec('200','c') );
757                          marc_duplicate;                          marc_duplicate;
758                            marc_leader('11',2);
759                          marc_remove('900','b');                          marc_remove('900','b');
760                          marc('900', 'b', rec('200','d') );                          marc('900', 'b', rec('200','d') );
761                          marc_duplicate;                          marc_duplicate;
762                            marc_leader('11',3);
763                          marc_remove('900','b');                          marc_remove('900','b');
764                          marc('900', 'b', rec('200','e') );                          marc('900', 'b', rec('200','e') );
765                  },                  },
# Line 747  sub test_s { Line 769  sub test_s {
769                  ],                  ],
770          );          );
771    
772            cmp_ok( marc_count(), '==', 3, 'marc_count' );
773    
774          my $i = 0;          my $i = 0;
775          foreach my $v ( qw/bar baz bing bong/ ) {          foreach my $v ( qw/bar baz bing bong/ ) {
776    
# Line 758  sub test_s { Line 782  sub test_s {
782                          [ [ '900', ' ', ' ', 'a', 42, 'b', $v ] ],                          [ [ '900', ' ', ' ', 'a', 42, 'b', $v ] ],
783                          "MARC copy $i has $v",                          "MARC copy $i has $v",
784                  );                  );
785                    is_deeply(WebPAC::Normalize::_get_marc_leader(), { '06' => 42, 11 => $i }, "_get_marc_leader copy $i");
786                  $i++;                  $i++;
787          }          }
788    
# Line 816  sub test_s { Line 841  sub test_s {
841                  '^aa1^bb1^aa2^bb2^cc1^cc2',                  '^aa1^bb1^aa2^bb2^cc1^cc2',
842                  '_pack_subfields_hash( $h, 1 )'                  '_pack_subfields_hash( $h, 1 )'
843          );          );
844    
845            _clean_ds();
846            test_s(qq{
847                    marc_fixed('008', 0, 'abcdef');
848                    marc_fixed('000', 5, '5');
849                    marc_fixed('000', 10, 'A');
850                    marc_fixed('000', 0, '0');
851            });
852            ok( my $m = WebPAC::Normalize::_get_marc_fields(), '_get_marc_fields');
853            diag dump( $m );
854            is_deeply( WebPAC::Normalize::_get_marc_fields(),
855                    [
856                            ["008", "abcdef"],
857                            #        0....5....10
858                            ["000", "0    5    A"]
859                    ]
860            );
861  }  }
862    

Legend:
Removed from v.725  
changed lines
  Added in v.912

  ViewVC Help
Powered by ViewVC 1.1.26