2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 24; |
use Test::More tests => 31; |
6 |
use Test::Exception; |
use Test::Exception; |
7 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
8 |
use File::Temp qw/tempdir/; |
use File::Temp qw/tempdir/; |
9 |
use File::Slurp; |
use File::Slurp; |
10 |
use Data::Dumper; |
use Data::Dump qw/dump/; |
11 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
12 |
use blib; |
use blib; |
13 |
|
|
14 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
15 |
|
|
16 |
|
# |
17 |
|
# FIXME add lookup testing! |
18 |
|
# |
19 |
|
|
20 |
BEGIN { |
BEGIN { |
|
use_ok( 'WebPAC::Lookup' ); |
|
21 |
use_ok( 'WebPAC::Input' ); |
use_ok( 'WebPAC::Input' ); |
22 |
use_ok( 'WebPAC::Store' ); |
use_ok( 'WebPAC::Store' ); |
|
use_ok( 'WebPAC::Lookup::Normalize' ); |
|
23 |
use_ok( 'WebPAC::Normalize' ); |
use_ok( 'WebPAC::Normalize' ); |
24 |
use_ok( 'WebPAC::Output::TT' ); |
use_ok( 'WebPAC::Output::TT' ); |
25 |
} |
} |
37 |
my $normalize_set_pl = "$abs_path/data/normalize.pl"; |
my $normalize_set_pl = "$abs_path/data/normalize.pl"; |
38 |
my $lookup_file = "$abs_path../conf/lookup/isis.pm"; |
my $lookup_file = "$abs_path../conf/lookup/isis.pm"; |
39 |
|
|
|
ok(my $lookup = new WebPAC::Lookup( |
|
|
lookup_file => $lookup_file, |
|
|
), "new Lookup"); |
|
|
|
|
40 |
ok(my $isis = new WebPAC::Input( |
ok(my $isis = new WebPAC::Input( |
41 |
module => 'WebPAC::Input::ISIS', |
module => 'WebPAC::Input::ISIS', |
42 |
code_page => 'ISO-8859-2', # application encoding |
code_page => 'ISO-8859-2', # application encoding |
46 |
|
|
47 |
ok(my $maxmfn = $isis->open( |
ok(my $maxmfn = $isis->open( |
48 |
path => $isis_file, |
path => $isis_file, |
49 |
code_page => '852', # database encoding |
code_page => 'cp852', # database encoding |
50 |
lookup_coderef => sub { |
lookup_coderef => sub { |
51 |
my $rec = shift || return; |
my $rec = shift || return; |
52 |
$lookup->add( $rec ); |
ok($rec, 'lookup_coderef has rec'); |
53 |
|
ok(defined($rec->{'000'}->[0]), 'have mfn'); |
54 |
}, |
}, |
55 |
), "Input::ISIS->open"); |
), "Input::ISIS->open"); |
56 |
|
|
57 |
ok(my $path = tempdir( CLEANUP => 1 ), "path"); |
ok(my $path = tempdir( CLEANUP => 1 ), "path"); |
58 |
|
|
59 |
ok(my $db = new WebPAC::Store( |
ok(my $db = new WebPAC::Store({ |
|
path => $path, |
|
60 |
database => '.', |
database => '.', |
61 |
), "new Store"); |
}), "new Store"); |
62 |
|
|
63 |
ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" ); |
ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" ); |
64 |
|
|
67 |
filters => { foo => sub { shift } }, |
filters => { foo => sub { shift } }, |
68 |
), "new Output::TT"); |
), "new Output::TT"); |
69 |
|
|
|
diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug); |
|
|
|
|
70 |
my $t_norm = 0; |
my $t_norm = 0; |
71 |
|
|
72 |
foreach my $pos ( 0 ... $isis->size ) { |
foreach my $pos ( 0 ... $isis->size ) { |
73 |
|
|
74 |
my $row = $isis->fetch || next; |
my $row = $isis->fetch || next; |
75 |
|
|
76 |
diag " row $pos => ",Dumper($row) if ($debug); |
diag " row $pos => ",dump($row) if ($debug); |
77 |
|
|
78 |
my $t = time(); |
my $t = time(); |
79 |
ok( my $ds = WebPAC::Normalize::data_structure( |
ok( my $ds = WebPAC::Normalize::data_structure( |
|
lookup => $lookup->lookup_hash, |
|
80 |
row => $row, |
row => $row, |
81 |
rules => $norm_pl, |
rules => $norm_pl, |
82 |
), "Set data_structure"); |
), "Set data_structure"); |
83 |
$t_norm += time() - $t; |
$t_norm += time() - $t; |
84 |
|
|
85 |
diag " ds $pos => ",Dumper($ds) if ($debug); |
diag " ds $pos => ",dump($ds) if ($debug); |
86 |
|
|
87 |
ok(my $html = $out->apply( |
ok(my $html = $out->apply( |
88 |
template => 'html.tt', |
template => 'html.tt', |