2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 23; |
use Test::More tests => 25; |
6 |
use Test::Exception; |
use Test::Exception; |
7 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
8 |
use blib; |
use blib; |
9 |
use File::Slurp; |
use File::Slurp; |
10 |
|
|
11 |
use Data::Dumper; |
use Data::Dumper; |
12 |
|
my $debug = 0; |
13 |
|
|
14 |
BEGIN { |
BEGIN { |
15 |
use_ok( 'WebPAC::Normalize::Set' ); |
use_ok( 'WebPAC::Normalize::Set' ); |
17 |
|
|
18 |
ok(my $abs_path = abs_path($0), "abs_path"); |
ok(my $abs_path = abs_path($0), "abs_path"); |
19 |
$abs_path =~ s#/[^/]*$#/../#; |
$abs_path =~ s#/[^/]*$#/../#; |
20 |
#diag "abs_path: $abs_path"; |
diag "abs_path: $abs_path" if ($debug); |
21 |
|
|
22 |
#throws_ok { new WebPAC::Normalize::XML( lookup_regex => 'foo' ) } qr/pair/, "lookup_regex without lookup"; |
#throws_ok { new WebPAC::Normalize::XML( lookup_regex => 'foo' ) } qr/pair/, "lookup_regex without lookup"; |
23 |
|
|
24 |
my $rec = { |
my $rec1 = { |
25 |
|
'200' => [{ |
26 |
|
'a' => '200a', |
27 |
|
'b' => '200b', |
28 |
|
},{ |
29 |
|
'c' => '200c', |
30 |
|
'd' => '200d', |
31 |
|
},{ |
32 |
|
'a' => '200a*2', |
33 |
|
'd' => '200d*2', |
34 |
|
}], |
35 |
|
'201' => [{ |
36 |
|
'x' => '201x', |
37 |
|
'y' => '201y', |
38 |
|
}], |
39 |
|
'900' => [ |
40 |
|
'900-no_subfield' |
41 |
|
], |
42 |
|
'901' => [{ |
43 |
|
'a' => '900a', |
44 |
|
}], |
45 |
|
'902' => [{ |
46 |
|
'z' => '900', |
47 |
|
}], |
48 |
|
}; |
49 |
|
|
50 |
|
my $rec2 = { |
51 |
'675' => [ { |
'675' => [ { |
52 |
'a' => '159.9' |
'a' => '159.9' |
53 |
} ], |
} ], |
93 |
'101' => [ 'ENG' ], |
'101' => [ 'ENG' ], |
94 |
'686' => [ '2140' ], |
'686' => [ '2140' ], |
95 |
'300' => [ 'Prijevod djela: ' ], |
'300' => [ 'Prijevod djela: ' ], |
|
'999' => [ { 'z' => '900' } ], |
|
96 |
}; |
}; |
97 |
|
|
98 |
|
|
99 |
my $lookup = { |
my $lookup1 = { |
100 |
'00900' => [ |
'00900' => [ |
101 |
'lookup vrijednost 1', |
'lookup 1', |
102 |
'lookup vrijednost 2', |
'lookup 2', |
103 |
], |
], |
104 |
}; |
}; |
105 |
|
|
106 |
print Dumper($rec); |
my $lookup2 = { |
107 |
|
'00900' => 'lookup', |
108 |
|
}; |
109 |
|
|
110 |
|
|
111 |
sub test { |
sub test { |
112 |
print Dumper( @_ ), ("-" x 78), "\n"; |
print Dumper( @_ ), ("-" x 78), "\n"; |
117 |
my $t = shift || die; |
my $t = shift || die; |
118 |
$t =~ s/[\n\r\s]+/ /gs; |
$t =~ s/[\n\r\s]+/ /gs; |
119 |
ok(my $v = eval "$t", "eval: $t"); |
ok(my $v = eval "$t", "eval: $t"); |
120 |
ok(! $@, "eval error: $@"); |
ok(! $@, $@ ? "error: $@" : "no error"); |
121 |
} |
} |
122 |
|
|
123 |
{ |
{ |
124 |
no strict 'subs'; |
no strict 'subs'; |
125 |
use WebPAC::Normalize::Set; |
use WebPAC::Normalize::Set; |
126 |
|
|
127 |
set_rec( $rec ); |
set_rec( $rec1 ); |
128 |
|
|
129 |
|
cmp_ok( join(",", rec2('200','a') ), 'eq', '200a,200a*2' ); |
130 |
|
cmp_ok( join(",", rec2('200','a'), rec2('200','b') ), 'eq', '200a,200a*2,200b' ); |
131 |
|
cmp_ok( join(" * ", sort(rec1('200'), rec1('201') )), 'eq', '200a * 200a*2 * 200b * 200c * 200d * 200d*2 * 201x * 201y' ); |
132 |
|
is_deeply( \[ rec1('200') ], \[ qw/200a 200b 200c 200d 200a*2 200d*2/ ] ); |
133 |
|
is_deeply( \[ regex( 's/0/o/g', rec1('200') ) ], \[ qw/2ooa 2oob 2ooc 2ood 2ooa*2 2ood*2/ ]); |
134 |
|
is_deeply( \[ grep { /\*/ } regex( 's/0/o/g', rec1('200') ) ], \[ qw/2ooa*2 2ood*2/ ]); |
135 |
|
is_deeply( \[ rec('902') ], \[ '900' ] ); |
136 |
|
cmp_ok( rec('902'), 'eq', rec('902','z') ); |
137 |
|
|
138 |
test( join(",", rec2('200','a') ) ); |
set_lookup( $lookup1 ); |
139 |
test( join(",", rec2('200','a'), rec2('200','b') ) ); |
|
140 |
test( join(" * ",rec1('200'), rec1('201') ) ); |
cmp_ok( |
|
test( rec1('200') ); |
|
|
test( regex( 's/0/o/g', rec1('200') ) ); |
|
|
test( grep { /\*/ } regex( 's/0/o/g', rec1('200') ) ); |
|
|
test( rec('999') ); |
|
|
test( rec('999','z') ); |
|
|
test( |
|
141 |
join_with(" i ", |
join_with(" i ", |
142 |
lookup( |
lookup( |
143 |
regex( 's/^/00/', |
regex( 's/^/00/', |
144 |
rec2('999','z') |
rec2('902','z') |
145 |
) |
) |
146 |
) |
) |
147 |
) |
), |
148 |
); |
'eq', 'lookup 1 i lookup 2'); |
149 |
|
|
150 |
|
set_lookup( $lookup2 ); |
151 |
|
|
152 |
|
is_deeply( \[ lookup( prefix( '00', rec('902') ) ) ], \[ 'lookup' ] ); |
153 |
|
|
154 |
|
ok(! lookup('non-existent') ); |
155 |
|
|
156 |
|
set_rec( $rec2 ); |
157 |
|
|
158 |
test_s(qq{ |
test_s(qq{ |
159 |
tag('Title', |
tag('Title', |
184 |
}); |
}); |
185 |
|
|
186 |
ok(my $ds = get_ds(), "get_ds"); |
ok(my $ds = get_ds(), "get_ds"); |
187 |
diag "ds = ", Dumper($ds); |
diag "ds = ", Dumper($ds) if ($debug); |
188 |
|
|
189 |
clean_ds(); |
clean_ds(); |
190 |
|
|
194 |
test_s( $n ); |
test_s( $n ); |
195 |
|
|
196 |
ok($ds = get_ds(), "get_ds"); |
ok($ds = get_ds(), "get_ds"); |
197 |
diag "ds = ", Dumper($ds); |
diag "ds = ", Dumper($ds) if ($debug); |
198 |
} |
} |
199 |
|
|