1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use Test::More tests => 92; |
use Test::More tests => 132; |
4 |
use Test::Exception; |
use Test::Exception; |
5 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
6 |
use blib; |
use blib; |
121 |
if (ref($item) eq 'HASH') { |
if (ref($item) eq 'HASH') { |
122 |
foreach my $sf (keys %$item) { |
foreach my $sf (keys %$item) { |
123 |
my $found = 0; |
my $found = 0; |
124 |
ok($n->get_data(\$rec, $fld, $sf, $r, \$found), "v${fld}^${sf}"); |
ok($n->get_data(\$rec, $fld, $sf, $r, \$found), "v${fld}^${sf} / $r"); |
125 |
ok($found, "found"); |
ok($found, "found"); |
126 |
} |
} |
127 |
my $found = 0; |
my $found = 0; |
128 |
ok(! $n->get_data(\$rec, $fld, 'x', $r, \$found), "no v${fld}^x"); |
ok(! $n->get_data(\$rec, $fld, 'x', $r, \$found), "no v${fld}^x / $r"); |
129 |
ok(! $found, "not found"); |
ok(! $found, "not found"); |
130 |
} else { |
} else { |
131 |
my $found = 0; |
my $found = 0; |
132 |
ok($n->get_data(\$rec, $fld, '', $r, \$found), "v${fld}"); |
ok($n->get_data(\$rec, $fld, undef, $r, \$found), "v${fld} / $r"); |
133 |
ok($found, "found"); |
ok($found, "found"); |
134 |
} |
} |
135 |
} |
} |
136 |
my $found = 0; |
my $found = 0; |
137 |
ok(! $n->get_data(\$rec, '999', '', $r, \$found), "no v${fld}"); |
ok(! $n->get_data(\$rec, '999', '', $r, \$found), "no v${fld} / $r"); |
138 |
ok(! $found, "not found"); |
ok(! $found, "not found"); |
139 |
} |
} |
140 |
|
|
163 |
] }, |
] }, |
164 |
}; |
}; |
165 |
|
|
166 |
sub parse_test($$$$) { |
sub parse_test($$$$$) { |
167 |
my ($import,$rec,$i,$r) = @_; |
my ($import,$tag,$rec,$i,$r) = @_; |
168 |
$n->{import_xml}->{indexer} = $import; |
$n->{import_xml}->{indexer} = $import; |
169 |
# erase internal cache (yak!) |
# erase internal cache (yak!) |
170 |
delete($n->{tags_by_order}); |
delete($n->{tags_by_order}); |
171 |
push @{$rec->{'000'}}, 42 unless ($rec->{'000'}); |
push @{$rec->{'000'}}, 42 unless ($rec->{'000'}); |
172 |
#diag "test normalisation of: ",Dumper($n->{import_xml}->{indexer}, $rec); |
#diag "test normalisation of: ",Dumper($n->{import_xml}->{indexer}, $rec); |
173 |
ok(my $ds = $n->data_structure( $rec ), "data_structure"); |
ok(my $ds = $n->data_structure( $rec ), "data_structure"); |
174 |
#diag Dumper($ds); |
diag Dumper($ds) if ($i == 0); |
175 |
cmp_ok($ds->{Tag}->{display}->[$i], 'eq', $r, "parse $i: $r"); |
cmp_ok($ds->{$tag}->{display}->[$i], 'eq', $r, "parse $tag/$i - $r"); |
176 |
} |
} |
177 |
|
|
178 |
parse_test($import, $rec, 0, '1 + 2 = 3 [yap]'); |
parse_test($import, 'Tag', $rec, 0, '1 + 2 = 3 [yap]'); |
179 |
|
|
180 |
delete($rec->{'900'}->[0]->{'b'}); |
delete($rec->{'900'}->[0]->{'b'}); |
181 |
parse_test($import, $rec, 0, '1 = 3 [yap]'); |
parse_test($import, 'Tag', $rec, 0, '1 = 3 [yap]'); |
182 |
|
|
183 |
$rec->{'900'}->[0]->{'b'} = 5; |
$rec->{'900'}->[0]->{'b'} = 5; |
184 |
$rec->{'900'}->[0]->{'c'} = 6; |
$rec->{'900'}->[0]->{'c'} = 6; |
185 |
parse_test($import, $rec, 0, '1 + 5 = 6 [yap]'); |
parse_test($import, 'Tag', $rec, 0, '1 + 5 = 6 [yap]'); |
186 |
|
|
187 |
delete($rec->{'900'}->[0]->{'c'}); |
delete($rec->{'900'}->[0]->{'c'}); |
188 |
$rec->{'900'}->[0]->{'x'} = 'hmmm'; |
$rec->{'900'}->[0]->{'x'} = 'hmmm'; |
189 |
parse_test($import, $rec, 0, '1 + 5 [hmmm]'); |
parse_test($import, 'Tag', $rec, 0, '1 + 5 [hmmm]'); |
190 |
|
|
191 |
$rec->{'900'}->[0]->{'x'} = 'nope!'; |
$rec->{'900'}->[0]->{'x'} = 'nope!'; |
192 |
delete($rec->{'900'}->[0]->{'a'}); |
delete($rec->{'900'}->[0]->{'a'}); |
193 |
parse_test($import, $rec, 0, '5 [nope!]'); |
parse_test($import, 'Tag', $rec, 0, '5 [nope!]'); |
194 |
|
|
195 |
$rec = { |
$rec = { |
196 |
'900' => [ { |
'900' => [ { |
218 |
] }, |
] }, |
219 |
}; |
}; |
220 |
|
|
221 |
parse_test($import, $rec, 0, '0 b1 3 b1 4'); |
parse_test($import, 'Tag', $rec, 0, '0 b1 3 b1 4'); |
222 |
parse_test($import, $rec, 1, '0 a1 1 b2 3 a1_b2 4'); |
parse_test($import, 'Tag', $rec, 1, '0 a1 1 b2 3 a1_b2 4'); |
223 |
parse_test($import, $rec, 2, '0 b3 2 c1 3 b3_c1 4'); |
parse_test($import, 'Tag', $rec, 2, '0 b3 2 c1 3 b3_c1 4'); |
224 |
parse_test($import, $rec, 3, '0 a2 1 b4 2 c2 3 a2_b4_c2 4'); |
parse_test($import, 'Tag', $rec, 3, '0 a2 1 b4 2 c2 3 a2_b4_c2 4'); |
225 |
|
|
226 |
|
sub parse_test_arr($$$$) { |
227 |
|
my ($import, $tag, $rec, $arr) = @_; |
228 |
|
my $i = 0; |
229 |
|
foreach my $res (@{$arr}) { |
230 |
|
parse_test($import, $tag, $rec, $i, $res); |
231 |
|
$i++; |
232 |
|
} |
233 |
|
} |
234 |
|
|
235 |
|
my $import = { |
236 |
|
'Tag_a' => { 'isis' => [ |
237 |
|
{ content => 'v900^a' }, |
238 |
|
] }, |
239 |
|
'Tag_b' => { 'isis' => [ |
240 |
|
{ content => 'v900^b' }, |
241 |
|
] }, |
242 |
|
'Tag_c' => { 'isis' => [ |
243 |
|
{ content => 'v900^c' }, |
244 |
|
] }, |
245 |
|
'Tag_x' => { 'isis' => [ |
246 |
|
{ content => 'v900^x' }, |
247 |
|
] }, |
248 |
|
'Tag_s1' => { 'isis' => [ |
249 |
|
{ content => 's900^b = s900^x' }, |
250 |
|
] }, |
251 |
|
'Tag_s2' => { 'isis' => [ |
252 |
|
{ content => 's900^a s900^b s900^c s900^x' }, |
253 |
|
] }, |
254 |
|
}; |
255 |
|
|
256 |
|
parse_test_arr($import, 'Tag_a', $rec, [ '','a1','','a2' ] ); |
257 |
|
parse_test_arr($import, 'Tag_b', $rec, [ 'b1','b2','b3','b4' ] ); |
258 |
|
parse_test_arr($import, 'Tag_c', $rec, [ '','','c1','c2' ] ); |
259 |
|
parse_test_arr($import, 'Tag_x', $rec, [ 'b1','a1_b2','b3_c1','a2_b4_c2' ] ); |
260 |
|
parse_test_arr($import, 'Tag_s1', $rec, [ 'b1 = b1', 'b1 = b1', 'b1 = b1', 'b1 = b1' ] ); |
261 |
|
|