/[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 724 by dpavlin, Mon Sep 11 14:29:01 2006 UTC revision 725 by dpavlin, Fri Sep 29 18:55:41 2006 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 157;  use Test::More tests => 309;
6  use Test::Exception;  use Test::Exception;
7  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
8  use blib;  use blib;
# Line 32  ok(my $abs_path = abs_path($0), "abs_pat Line 32  ok(my $abs_path = abs_path($0), "abs_pat
32  $abs_path =~ s#/[^/]*$#/#;  $abs_path =~ s#/[^/]*$#/#;
33  diag "abs_path: $abs_path" if ($debug);  diag "abs_path: $abs_path" if ($debug);
34    
 #throws_ok { new WebPAC::Normalize::XML( lookup_regex => 'foo' ) } qr/pair/, "lookup_regex without lookup";  
   
35  my $rec1 = {  my $rec1 = {
36          '200' => [{          '200' => [{
37                  'a' => '200a',                  'a' => '200a',
# Line 109  my $rec2 = { Line 107  my $rec2 = {
107  };  };
108    
109    
110  my $lookup1 = {  my $lookup_hash1 = {
111          '00900' => [          'db1' => {
112                  'lookup 1',                  'input1' => {
113                  'lookup 2',                          'key1' => { 1 => 1 },
114          ],                          'key2' => { 2 => 1 },
115                    },
116                    'input2' => {
117                            'key3' => { 3 => 1 },
118                            'key4' => { 4 => 1 },
119                    },
120            },
121            'db2' => {
122                    'input3' => {
123                            'key5' => { 5 => 1 },
124                            'key6' => { 6 => 1 },
125                    },
126            }
127  };  };
128    
129  my $lookup2 = {  my $lookup_hash2 = {
130          '00900' => 'lookup',          'db3' => {
131                    'input4' => {
132                            'key7' => { 7 => 1 },
133                            'key8' => { 8 => 1 },
134                    },
135            }
136  };  };
137    
   
138  sub test {  sub test {
139          print dump( @_ ), ("-" x 78), "\n";          print dump( @_ ), ("-" x 78), "\n";
140          ok( defined(@_) );          ok( defined(@_) );
# Line 180  sub test_s { Line 194  sub test_s {
194          cmp_ok( join('', suffix('xy', 'cd') ), 'eq', 'cdxy', 'suffix');          cmp_ok( join('', suffix('xy', 'cd') ), 'eq', 'cdxy', 'suffix');
195          cmp_ok( join('', surround('->', '<-', 'a','b','c') ), 'eq', '->a<-->b<-->c<-', 'surround');          cmp_ok( join('', surround('->', '<-', 'a','b','c') ), 'eq', '->a<-->b<-->c<-', 'surround');
196    
197            # lookups
198    
199            throws_ok { _set_load_ds() } qr/CODE/, 'empty _set_load_ds()';
200    
201            ok(_set_load_ds(sub {
202                    my ($database,$input,$mfn) = @_;
203                    diag "load_ds( $database, $input, $mfn )";
204                    cmp_ok( $#_, '==', 2, 'have 3 arguments');
205                    ok($database, '_load_ds database');
206                    ok($input, '_load_ds input');
207                    ok($mfn, '_load_ds mfn');
208                    return {
209                            '900' => [{ x => '900x-' . $mfn , y => '900y-' . $mfn }],
210                    }
211    
212            }), '_set_load_ds');
213    
214            my @v = qw/foo bar baz aaa bbb ccc ddd/;
215    
216            my @accumulated;
217    
218            for my $i ( 0 .. $#v ) {
219    
220                    my $mfn = 1000 + $i;
221    
222                    ok(WebPAC::Normalize::_set_config({ '_mfn' => $mfn }), "_set_config _mfn=$mfn");
223    
224                    my $size = $#v + 1;
225    
226                    cmp_ok(
227                            save_into_lookup('db','input','key', sub { @v }),
228                            '==', $size, "save_into_lookup $size values"
229                    );
230    
231                    ok(my $l = WebPAC::Normalize::_get_lookup(), '_get_lookup');
232                    diag "_get_lookup = ", dump($l);
233    
234                    my @lookup;
235    
236                    ok(my @lookup = lookup(
237                                    sub {
238                                            diag "in show";
239                                            rec('900','x');
240                                    },
241                                    'db','input','key',
242                                    sub {
243                                            return @v;
244                                    }
245                            ),
246                    "lookup db/input/key");
247    
248                    push @accumulated, '900x-' . $mfn;
249    
250                    is_deeply(\@lookup, \@accumulated, "lookup db/input/key");
251    
252                    shift @v;
253    
254            }
255    
256            ok(my $l = WebPAC::Normalize::_get_lookup(), '_get_lookup');
257            diag "_get_lookup = ", dump($l);
258    
259            is_deeply( $l, {
260                    db => {
261                            input => {
262                                    key => {
263                                            foo => { 1000 => 1 },
264                                            bar => { 1000 => 1, 1001 => 1 },
265                                            baz => { 1000 => 1, 1001 => 1, 1002 => 1 },
266                                            aaa => { 1000 => 1, 1001 => 1, 1002 => 1, 1003 => 1 },
267                                            bbb => { 1000 => 1, 1001 => 1, 1002 => 1, 1003 => 1, 1004 => 1 },
268                                            ccc => { 1000 => 1, 1001 => 1, 1002 => 1, 1003 => 1, 1004 => 1, 1005 => 1 },
269                                            ddd => { 1000 => 1, 1001 => 1, 1002 => 1, 1003 => 1, 1004 => 1, 1005 => 1, 1006 => 1 },
270                                    },
271                            },
272                    },
273            }, 'lookup data');
274    
275    #######
276    
277            diag "lookup_hash1 = ", dump($lookup_hash1);
278            ok(_set_lookup( $lookup_hash1 ), '_set_lookup $lookup_hash1');
279    
280            throws_ok { _set_load_ds() } qr/CODE/, 'empty _set_load_ds()';
281    
282            ok(_set_load_ds(sub {
283                    my ($database,$input,$mfn) = @_;
284                    diag "load_ds( $database, $input, $mfn )";
285                    cmp_ok( $#_, '==', 2, 'have 3 arguments');
286                    ok($database, 'database');
287                    ok($input, 'input');
288                    ok($mfn, 'mfn');
289    
290            }), '_set_load_ds');
291    
292    
293    #       cmp_ok(lookup(
294    #               sub {
295    #                       'found'
296    #               },
297    #               'db1','input1','key1',
298    #               sub {
299    #                       rec('200','a')
300    #               }
301    #       ), 'eq', 'found', 'lookup db1/input1/key1');
302    
303    
         _set_lookup( $lookup1 );  
304                    
305          cmp_ok(  #       cmp_ok(
306                  join_with(" i ",  #               lookup(
307                          lookup(  #               ),
308                                  regex( 's/^/00/',  #       'eq', 'lookup 1 i lookup 2', 'join lookup regex rec2');
                                         rec2('902','z')  
                                 )  
                         )  
                 ),  
         'eq', 'lookup 1 i lookup 2', 'join lookup regex rec2');  
309    
310          # check join_with operations          # check join_with operations
311    
# Line 235  sub test_s { Line 349  sub test_s {
349    
350          # test lookups          # test lookups
351    
352          _set_lookup( $lookup2 );          _set_lookup( $lookup_hash2 );
353    
354            throws_ok { lookup() } qr/need/, 'empty lookup';
355    
356          is_deeply( \[ lookup( prefix( '00', rec('902') ) ) ], \[ 'lookup' ], 'lookup prefix' );          #is_deeply( \[ lookup( prefix( '00', rec('902') ) ) ], \[ 'lookup' ], 'lookup prefix' );
357    
358          ok(! lookup('non-existent'), 'lookup non-existant' );          #ok(! lookup('non-existent'), 'lookup non-existant' );
359    
360          _set_rec( $rec2 );          _set_rec( $rec2 );
361    
# Line 360  sub test_s { Line 476  sub test_s {
476          #          #
477          # MARC          # MARC
478          #          #
479          _debug( 4 );          #_debug( 4 );
480    
481          test_s(qq{ marc_indicators('900',1,2) });          test_s(qq{ marc_indicators('900',1,2) });
482          test_s(qq{ marc('900','a', rec('200') ) });          test_s(qq{ marc('900','a', rec('200') ) });

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

  ViewVC Help
Powered by ViewVC 1.1.26