/[webpac2]/trunk/t/3-normalize-set.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/3-normalize-set.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 461 - (show annotations)
Fri May 12 14:54:25 2006 UTC (17 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 3075 byte(s)
 r581@llin:  dpavlin | 2006-05-12 16:57:30 +0200
 added clean_ds, rec1 now supports fields without subfields, rec1 & rec2 now take special care
 not to auto-vivify fields, removed various cruft, tidy pod

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Test::More tests => 23;
6 use Test::Exception;
7 use Cwd qw/abs_path/;
8 use blib;
9 use File::Slurp;
10
11 use Data::Dumper;
12
13 BEGIN {
14 use_ok( 'WebPAC::Normalize::Set' );
15 }
16
17 ok(my $abs_path = abs_path($0), "abs_path");
18 $abs_path =~ s#/[^/]*$#/../#;
19 #diag "abs_path: $abs_path";
20
21 #throws_ok { new WebPAC::Normalize::XML( lookup_regex => 'foo' ) } qr/pair/, "lookup_regex without lookup";
22
23 my $rec = {
24 '675' => [ {
25 'a' => '159.9'
26 } ],
27 '210' => [ {
28 'c' => 'New York University press',
29 'a' => 'New York',
30 'd' => 'cop. 1988'
31 } ],
32 '700' => [ {
33 'a' => 'Haynal',
34 'b' => 'André'
35 } ],
36 '801' => [ 'FFZG' ],
37 '991' => [ '8302' ],
38 '000' => [ 1 ],
39 '702' => [ {
40 'a' => 'Holder',
41 'b' => 'Elizabeth'
42 } ],
43 '215' => [ {
44 'c' => 'ilustr',
45 'a' => 'xix, 202 str',
46 'd' => '23cm'
47 } ],
48 '990' => [
49 '2140',
50 '88',
51 'HAY'
52 ],
53 '200' => [ {
54 'e' => 'from Freud and Ferenczi to Michael balint',
55 'a' => 'Controversies in psychoanalytic method',
56 'g' => 'translated by Elizabeth Holder on the basisi of a first draft by Archie Hooton ; with a preface by Daniel N. Stern',
57 'f' => 'by André E. Haynal'
58 } ],
59 '610' => [ 'povijest psihoanalize' ],
60 '994' => [ {
61 'c' => '',
62 'a' => 'PS',
63 'b' => 'MG'
64 } ],
65 '320' => [ 'Kazalo' ],
66 '101' => [ 'ENG' ],
67 '686' => [ '2140' ],
68 '300' => [ 'Prijevod djela: ' ],
69 '999' => [ { 'z' => '900' } ],
70 };
71
72
73 my $lookup = {
74 '00900' => [
75 'lookup vrijednost 1',
76 'lookup vrijednost 2',
77 ],
78 };
79
80 print Dumper($rec);
81
82 sub test {
83 print Dumper( @_ ), ("-" x 78), "\n";
84 ok( defined(@_) );
85 }
86
87 sub test_s {
88 my $t = shift || die;
89 $t =~ s/[\n\r\s]+/ /gs;
90 ok(my $v = eval "$t", "eval: $t");
91 ok(! $@, "eval error: $@");
92 }
93
94 {
95 no strict 'subs';
96 use WebPAC::Normalize::Set;
97
98 set_rec( $rec );
99
100 test( join(",", rec2('200','a') ) );
101 test( join(",", rec2('200','a'), rec2('200','b') ) );
102 test( join(" * ",rec1('200'), rec1('201') ) );
103 test( rec1('200') );
104 test( regex( 's/0/o/g', rec1('200') ) );
105 test( grep { /\*/ } regex( 's/0/o/g', rec1('200') ) );
106 test( rec('999') );
107 test( rec('999','z') );
108 test(
109 join_with(" i ",
110 lookup(
111 regex( 's/^/00/',
112 rec2('999','z')
113 )
114 )
115 )
116 );
117
118 test_s(qq{
119 tag('Title',
120 rec('200','a')
121 );
122 });
123 test_s(qq{
124 tag('Who',
125 join_with(" ",
126 rec('702','a'),
127 rec('702','b')
128 )
129 );
130 });
131
132 test_s(qq{
133 display('Publisher',
134 rec('210','c')
135 )
136 });
137
138 test_s(qq{
139 search('Year',
140 regex( 's/[^\\d]+//',
141 rec('210','d')
142 )
143 )
144 });
145
146 ok(my $ds = get_ds(), "get_ds");
147 diag "ds = ", Dumper($ds);
148
149 clean_ds();
150
151 my $n = read_file( "$abs_path/conf/normalize/isis_ffzg.pl" );
152 $n .= "\n1;\n";
153 #diag "normalize code:\n$n\n";
154 test_s( $n );
155
156 ok($ds = get_ds(), "get_ds");
157 diag "ds = ", Dumper($ds);
158 }
159

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26