/[webpac2]/trunk/t/1-lookup.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

Annotation of /trunk/t/1-lookup.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 478 - (hide annotations)
Sat May 13 13:38:53 2006 UTC (18 years ago) by dpavlin
File MIME type: application/x-troff
File size: 1368 byte(s)
 r616@llin:  dpavlin | 2006-05-13 15:40:49 +0200
 compare lookup_hash result

1 dpavlin 3 #!/usr/bin/perl -w
2    
3 dpavlin 4 use strict;
4 dpavlin 478 use Test::More tests => 18;
5 dpavlin 3 use Test::Exception;
6     use blib;
7    
8 dpavlin 4 use Data::Dumper;
9    
10 dpavlin 3 BEGIN {
11 dpavlin 4 use_ok( 'WebPAC::Lookup' );
12 dpavlin 3 }
13    
14 dpavlin 478 my $debug = shift @ARGV;
15    
16 dpavlin 31 throws_ok { new WebPAC::Lookup( no_log => 1 ) } qr/lookup_file/, "new without lookup_file";
17 dpavlin 3
18 dpavlin 5 ok(my $lookup = new WebPAC::Lookup(
19     lookup_file => 'conf/lookup/example.pm',
20     filter => {
21     'upper' => sub { return uc(shift); },
22     },
23     ), "new");
24 dpavlin 4
25 dpavlin 12 ok(my $regex = $lookup->regex, "regex");
26     diag "regex: $regex";
27    
28 dpavlin 4 my $rec = {
29     '000' => [ '001' ],
30     '800' => [ 'foo' ],
31     '900' => [ 'bar' ],
32     };
33    
34 dpavlin 7 diag "testing WebPAC::Lookup own methods";
35    
36 dpavlin 4 ok($lookup->add( $rec ), "add");
37    
38 dpavlin 478 ok(my $l1 = $lookup->{_lookup_data}, "{_lookup_data}");
39     diag "lookup->{_lookup_data} = ",Dumper($lookup->{_lookup_data}) if ($debug);
40     ok(my $l2 = $lookup->lookup_hash, "lookup_hash");
41     diag "lookup->lookup_hash = ",Dumper($lookup->lookup_hash) if ($debug);
42 dpavlin 4
43 dpavlin 478 is_deeply( $l1, $l2, 'lookups same');
44    
45 dpavlin 4 my $lookup_res = {
46     '800:foo' => [ 'bar' ],
47     '000:001' => [ '001' ],
48 dpavlin 5 '900:bar' => [ 'FOO', 'foo' ]
49 dpavlin 4 };
50    
51 dpavlin 30 is_deeply($lookup_res, $lookup->{'_lookup_data'}, "lookup data");
52 dpavlin 4
53 dpavlin 7 foreach my $k (keys %{ $lookup_res }) {
54     ok(my @l = $lookup->lookup("lookup{$k}"), "lookup{$k}");
55    
56     cmp_ok($#l, '==', $#{$lookup_res->{$k}}, "result size");
57    
58     is_deeply($lookup_res->{$k}, \@l, "result values");
59     }
60    
61     diag "testing WebPAC::Lookup inherited methods";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26