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