/[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

Annotation of /trunk/t/6-unit.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 887 - (hide annotations)
Mon Sep 3 15:26:46 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2097 byte(s)
 r1322@llin:  dpavlin | 2007-09-03 16:44:01 +0200
 - replace Data::Dumper usage with Data::Dump
 - rewrite WebPAC::Store to use Class::Accessor

1 dpavlin 22 #!/usr/bin/perl -w
2    
3     use strict;
4    
5 dpavlin 767 use Test::More tests => 31;
6 dpavlin 22 use Test::Exception;
7     use Cwd qw/abs_path/;
8     use File::Temp qw/tempdir/;
9 dpavlin 470 use File::Slurp;
10 dpavlin 887 use Data::Dump qw/dump/;
11 dpavlin 489 use Time::HiRes qw/time/;
12 dpavlin 22 use blib;
13    
14 dpavlin 474 my $debug = shift @ARGV;
15 dpavlin 470
16 dpavlin 767 #
17     # FIXME add lookup testing!
18     #
19    
20 dpavlin 22 BEGIN {
21 dpavlin 300 use_ok( 'WebPAC::Input' );
22 dpavlin 209 use_ok( 'WebPAC::Store' );
23 dpavlin 536 use_ok( 'WebPAC::Normalize' );
24 dpavlin 22 use_ok( 'WebPAC::Output::TT' );
25     }
26    
27     ok(my $abs_path = abs_path($0), "abs_path");
28     $abs_path =~ s#/[^/]*$#/#;
29 dpavlin 470 diag "abs_path: $abs_path" if ($debug);
30 dpavlin 22
31     my $isis_file = "$abs_path../t/winisis/BIBL";
32 dpavlin 479 #$isis_file = '/data/hidra/THS/THS';
33 dpavlin 536 #$isis_file = '/data/isis_data/ffkk/';
34 dpavlin 22
35 dpavlin 470 diag "isis_file: $isis_file" if ($debug);
36 dpavlin 22
37 dpavlin 470 my $normalize_set_pl = "$abs_path/data/normalize.pl";
38     my $lookup_file = "$abs_path../conf/lookup/isis.pm";
39    
40 dpavlin 300 ok(my $isis = new WebPAC::Input(
41     module => 'WebPAC::Input::ISIS',
42 dpavlin 22 code_page => 'ISO-8859-2', # application encoding
43 dpavlin 489 limit => 100,
44     no_progress_bar => 1,
45 dpavlin 22 ), "new Input::ISIS");
46    
47     ok(my $maxmfn = $isis->open(
48 dpavlin 300 path => $isis_file,
49 dpavlin 625 code_page => 'cp852', # database encoding
50 dpavlin 585 lookup_coderef => sub {
51     my $rec = shift || return;
52 dpavlin 767 ok($rec, 'lookup_coderef has rec');
53     ok(defined($rec->{'000'}->[0]), 'have mfn');
54 dpavlin 585 },
55 dpavlin 22 ), "Input::ISIS->open");
56    
57     ok(my $path = tempdir( CLEANUP => 1 ), "path");
58    
59 dpavlin 887 ok(my $db = new WebPAC::Store({
60 dpavlin 217 database => '.',
61 dpavlin 887 }), "new Store");
62 dpavlin 22
63 dpavlin 470 ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" );
64    
65 dpavlin 22 ok(my $out = new WebPAC::Output::TT(
66     include_path => "$abs_path../conf/output/tt",
67     filters => { foo => sub { shift } },
68     ), "new Output::TT");
69    
70 dpavlin 536 my $t_norm = 0;
71    
72 dpavlin 482 foreach my $pos ( 0 ... $isis->size ) {
73 dpavlin 470
74 dpavlin 482 my $row = $isis->fetch || next;
75    
76 dpavlin 887 diag " row $pos => ",dump($row) if ($debug);
77 dpavlin 474
78 dpavlin 489 my $t = time();
79 dpavlin 536 ok( my $ds = WebPAC::Normalize::data_structure(
80 dpavlin 491 row => $row,
81     rules => $norm_pl,
82     ), "Set data_structure");
83 dpavlin 536 $t_norm += time() - $t;
84 dpavlin 489
85 dpavlin 887 diag " ds $pos => ",dump($ds) if ($debug);
86 dpavlin 489
87 dpavlin 33 ok(my $html = $out->apply(
88 dpavlin 22 template => 'html.tt',
89 dpavlin 70 data => $ds,
90 dpavlin 22 ), "apply");
91    
92 dpavlin 33 $html =~ s#\s*[\n\r]+\s*##gs;
93    
94 dpavlin 352 #diag $html;
95 dpavlin 33
96 dpavlin 22 };
97 dpavlin 489
98 dpavlin 536 diag sprintf("timings: %.2fs\n", $t_norm);

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26