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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (show annotations)
Sat May 13 12:08:05 2006 UTC (18 years ago) by dpavlin
File MIME type: application/x-troff
File size: 2476 byte(s)
 r604@llin:  dpavlin | 2006-05-13 14:10:47 +0200
 better output, use lookup_hash

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Test::More tests => 66;
6 use Test::Exception;
7 use Cwd qw/abs_path/;
8 use File::Temp qw/tempdir/;
9 use File::Slurp;
10 use Data::Dumper;
11 use blib;
12
13 my $debug = shift @ARGV;
14
15 BEGIN {
16 use_ok( 'WebPAC::Lookup' );
17 use_ok( 'WebPAC::Input' );
18 use_ok( 'WebPAC::Store' );
19 use_ok( 'WebPAC::Normalize::XML' );
20 use_ok( 'WebPAC::Normalize::Set' );
21 use_ok( 'WebPAC::Output::TT' );
22 }
23
24 ok(my $abs_path = abs_path($0), "abs_path");
25 $abs_path =~ s#/[^/]*$#/#;
26 diag "abs_path: $abs_path" if ($debug);
27
28 my $isis_file = "$abs_path../t/winisis/BIBL";
29 $isis_file = '/data/hidra/THS/THS';
30
31 diag "isis_file: $isis_file" if ($debug);
32
33 my $normalize_set_pl = "$abs_path/data/normalize.pl";
34 my $lookup_file = "$abs_path../conf/lookup/isis.pm";
35
36 ok(my $lookup = new WebPAC::Lookup(
37 lookup_file => $lookup_file,
38 ), "new Lookup");
39
40 ok(my $isis = new WebPAC::Input(
41 module => 'WebPAC::Input::ISIS',
42 code_page => 'ISO-8859-2', # application encoding
43 limit => 10,
44 ), "new Input::ISIS");
45
46 ok(my $maxmfn = $isis->open(
47 path => $isis_file,
48 code_page => '852', # database encoding
49 lookup => $lookup,
50 ), "Input::ISIS->open");
51
52 ok(my $path = tempdir( CLEANUP => 1 ), "path");
53
54 ok(my $db = new WebPAC::Store(
55 path => $path,
56 database => '.',
57 ), "new Store");
58
59 ok(my $n = new WebPAC::Normalize::XML(
60 # filter => { 'foo' => sub { shift } },
61 db => $db,
62 lookup_regex => $lookup->regex,
63 lookup => $lookup,
64 ), "new Normalize::XML");
65
66 ok($n->open(
67 tag => 'isis',
68 xml_file => "$abs_path/data/normalize.xml",
69 ), "Normalize::XML->open");
70
71 ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" );
72
73 ok(my $out = new WebPAC::Output::TT(
74 include_path => "$abs_path../conf/output/tt",
75 filters => { foo => sub { shift } },
76 ), "new Output::TT");
77
78 while (my $row = $isis->fetch) {
79
80 diag " row => ",Dumper($row) if ($debug);
81 set_rec( $row );
82
83 ok(my $ds = $n->data_structure($row), "data_structure");
84
85 diag " ds => ",Dumper($ds) if ($debug);
86
87 # TODO move somewhere
88 {
89 no strict 'subs';
90 use WebPAC::Normalize::Set;
91 diag " lookup => ",Dumper($lookup) if ($debug);
92 set_lookup( $lookup->lookup_hash );
93 clean_ds();
94 eval "$norm_pl";
95 ok(! $@, $@ ? "error: $@" : "no error");
96 ok(my $ds2 = get_ds(), "get_ds");
97 is_deeply( $ds, $ds2, 'ds same for xml and sets');
98
99 diag " ds2 => ",Dumper($ds2) if ($debug);
100 }
101
102 ok(my $html = $out->apply(
103 template => 'html.tt',
104 data => $ds,
105 ), "apply");
106
107 $html =~ s#\s*[\n\r]+\s*##gs;
108
109 #diag $html;
110
111 };

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26