--- trunk/t/6-unit.t 2005/07/17 22:48:25 22 +++ trunk/t/6-unit.t 2006/05/13 12:07:27 470 @@ -2,74 +2,109 @@ use strict; -use Test::More tests => 23; +use Test::More tests => 66; use Test::Exception; use Cwd qw/abs_path/; use File::Temp qw/tempdir/; +use File::Slurp; +use Data::Dumper; use blib; +my $debug = 1; + BEGIN { use_ok( 'WebPAC::Lookup' ); -use_ok( 'WebPAC::Input::ISIS' ); -use_ok( 'WebPAC::DB' ); +use_ok( 'WebPAC::Input' ); +use_ok( 'WebPAC::Store' ); use_ok( 'WebPAC::Normalize::XML' ); +use_ok( 'WebPAC::Normalize::Set' ); use_ok( 'WebPAC::Output::TT' ); } ok(my $abs_path = abs_path($0), "abs_path"); $abs_path =~ s#/[^/]*$#/#; -diag "abs_path: $abs_path"; +diag "abs_path: $abs_path" if ($debug); my $isis_file = "$abs_path../t/winisis/BIBL"; +$isis_file = '/data/hidra/THS/THS'; + +diag "isis_file: $isis_file" if ($debug); -diag "isis_file: $isis_file"; +my $normalize_set_pl = "$abs_path/data/normalize.pl"; +my $lookup_file = "$abs_path../conf/lookup/isis.pm"; ok(my $lookup = new WebPAC::Lookup( - lookup_file => "$abs_path../conf/lookup/isis.pm", + lookup_file => $lookup_file, ), "new Lookup"); -ok(my $isis = new WebPAC::Input::ISIS( +ok(my $isis = new WebPAC::Input( + module => 'WebPAC::Input::ISIS', code_page => 'ISO-8859-2', # application encoding + limit => 10, ), "new Input::ISIS"); ok(my $maxmfn = $isis->open( - filename => $isis_file, + path => $isis_file, code_page => '852', # database encoding + lookup => $lookup, ), "Input::ISIS->open"); ok(my $path = tempdir( CLEANUP => 1 ), "path"); -ok(my $db = new WebPAC::DB( +ok(my $db = new WebPAC::Store( path => $path, -), "new DB"); + database => '.', +), "new Store"); ok(my $n = new WebPAC::Normalize::XML( # filter => { 'foo' => sub { shift } }, db => $db, lookup_regex => $lookup->regex, - debug => 1, + lookup => $lookup, ), "new Normalize::XML"); ok($n->open( tag => 'isis', - xml_file => "$abs_path../conf/normalize/isis.xml", + xml_file => "$abs_path/data/normalize.xml", ), "Normalize::XML->open"); +ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" ); + ok(my $out = new WebPAC::Output::TT( include_path => "$abs_path../conf/output/tt", filters => { foo => sub { shift } }, ), "new Output::TT"); while (my $row = $isis->fetch) { - - ok(my @ds = $n->data_structure($row), "data_structure"); -use Data::Dumper; -print Dumper(\@ds); + ok(my $ds = $n->data_structure($row), "data_structure"); - ok($out->apply( + diag " ds => ",Dumper($ds) if ($debug); + + # TODO move somewhere + { + no strict 'subs'; + use WebPAC::Normalize::Set; + diag " row => ",Dumper($row) if ($debug); + set_rec( $row ); + #diag " lookup => ",Dumper($lookup) if ($debug); + #set_lookup( $lookup ); + clean_ds(); + eval "$norm_pl"; + ok(! $@, $@ ? "error: $@" : "no error"); + ok(my $ds2 = get_ds(), "get_ds"); + is_deeply( $ds, $ds2, 'ds same for xml and sets'); + + diag " ds2 => ",Dumper($ds2) if ($debug); + } + + ok(my $html = $out->apply( template => 'html.tt', - data => @ds, + data => $ds, ), "apply"); + $html =~ s#\s*[\n\r]+\s*##gs; + + #diag $html; + };