/[webpac2]/trunk/t/6-unit.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/6-unit.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 479 by dpavlin, Sat May 13 13:39:09 2006 UTC revision 585 by dpavlin, Wed Jul 5 19:52:45 2006 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 66;  use Test::More tests => 24;
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::Dumper;
11    use Time::HiRes qw/time/;
12  use blib;  use blib;
13    
14  my $debug = shift @ARGV;  my $debug = shift @ARGV;
# Line 16  BEGIN { Line 17  BEGIN {
17  use_ok( 'WebPAC::Lookup' );  use_ok( 'WebPAC::Lookup' );
18  use_ok( 'WebPAC::Input' );  use_ok( 'WebPAC::Input' );
19  use_ok( 'WebPAC::Store' );  use_ok( 'WebPAC::Store' );
20  use_ok( 'WebPAC::Normalize::XML' );  use_ok( 'WebPAC::Lookup::Normalize' );
21  use_ok( 'WebPAC::Normalize::Set' );  use_ok( 'WebPAC::Normalize' );
22  use_ok( 'WebPAC::Output::TT' );  use_ok( 'WebPAC::Output::TT' );
23  }  }
24    
# Line 27  diag "abs_path: $abs_path" if ($debug); Line 28  diag "abs_path: $abs_path" if ($debug);
28    
29  my $isis_file = "$abs_path../t/winisis/BIBL";  my $isis_file = "$abs_path../t/winisis/BIBL";
30  #$isis_file = '/data/hidra/THS/THS';  #$isis_file = '/data/hidra/THS/THS';
31  $isis_file = '/data/isis_data/ffkk/';  #$isis_file = '/data/isis_data/ffkk/';
32    
33  diag "isis_file: $isis_file" if ($debug);  diag "isis_file: $isis_file" if ($debug);
34    
# Line 41  ok(my $lookup = new WebPAC::Lookup( Line 42  ok(my $lookup = new WebPAC::Lookup(
42  ok(my $isis = new WebPAC::Input(  ok(my $isis = new WebPAC::Input(
43          module => 'WebPAC::Input::ISIS',          module => 'WebPAC::Input::ISIS',
44          code_page => 'ISO-8859-2',      # application encoding          code_page => 'ISO-8859-2',      # application encoding
45          limit => 10,          limit => 100,
46            no_progress_bar => 1,
47  ), "new Input::ISIS");  ), "new Input::ISIS");
48    
49  ok(my $maxmfn = $isis->open(  ok(my $maxmfn = $isis->open(
50          path => $isis_file,          path => $isis_file,
51          code_page => '852',             # database encoding          code_page => '852',             # database encoding
52          lookup => $lookup,          lookup_coderef => sub {
53                    my $rec = shift || return;
54                    $lookup->add( $rec );
55            },
56  ), "Input::ISIS->open");  ), "Input::ISIS->open");
57    
58  ok(my $path = tempdir( CLEANUP => 1 ), "path");  ok(my $path = tempdir( CLEANUP => 1 ), "path");
# Line 57  ok(my $db = new WebPAC::Store( Line 62  ok(my $db = new WebPAC::Store(
62          database => '.',          database => '.',
63  ), "new Store");  ), "new Store");
64    
 ok(my $n = new WebPAC::Normalize::XML(  
 #       filter => { 'foo' => sub { shift } },  
         db => $db,  
         lookup_regex => $lookup->regex,  
         lookup => $lookup,  
 ), "new Normalize::XML");  
   
 ok($n->open(  
         tag => 'isis',  
         xml_file => "$abs_path/data/normalize.xml",  
 ), "Normalize::XML->open");  
   
65  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" );
66    
67  ok(my $out = new WebPAC::Output::TT(  ok(my $out = new WebPAC::Output::TT(
# Line 76  ok(my $out = new WebPAC::Output::TT( Line 69  ok(my $out = new WebPAC::Output::TT(
69          filters => { foo => sub { shift } },          filters => { foo => sub { shift } },
70  ), "new Output::TT");  ), "new Output::TT");
71    
72  while (my $row = $isis->fetch) {  diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug);
73    
74    my $t_norm = 0;
75    
76          diag " row => ",Dumper($row) if ($debug);  foreach my $pos ( 0 ... $isis->size ) {
         set_rec( $row );  
77    
78          ok(my $ds = $n->data_structure($row), "data_structure");          my $row = $isis->fetch || next;
79    
80          diag " ds => ",Dumper($ds) if ($debug);          diag " row $pos => ",Dumper($row) if ($debug);
81    
82          # TODO move somewhere          my $t = time();
83          {          ok( my $ds = WebPAC::Normalize::data_structure(
84                  no strict 'subs';                  lookup => $lookup->lookup_hash,
85                  use WebPAC::Normalize::Set;                  row => $row,
86                  diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug);                  rules => $norm_pl,
87                  set_lookup( $lookup->lookup_hash );          ), "Set data_structure");
88                  clean_ds();          $t_norm += time() - $t;
                 eval "$norm_pl";  
                 ok(! $@, $@ ? "error: $@" : "no error");  
                 ok(my $ds2 = get_ds(), "get_ds");  
                 is_deeply( $ds, $ds2, 'ds same for xml and sets');  
89    
90                  diag " ds2 => ",Dumper($ds2) if ($debug);          diag " ds $pos => ",Dumper($ds) if ($debug);
         }  
91    
92          ok(my $html = $out->apply(          ok(my $html = $out->apply(
93                  template => 'html.tt',                  template => 'html.tt',
# Line 110  while (my $row = $isis->fetch) { Line 99  while (my $row = $isis->fetch) {
99          #diag $html;          #diag $html;
100    
101  };  };
102    
103    diag sprintf("timings: %.2fs\n", $t_norm);

Legend:
Removed from v.479  
changed lines
  Added in v.585

  ViewVC Help
Powered by ViewVC 1.1.26