--- trunk/t/3-normalize-xml.t 2005/11/19 23:48:24 70 +++ trunk/t/3-normalize-xml.t 2005/12/23 21:17:37 315 @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::More tests => 74; +use Test::More tests => 76; use Test::Exception; use Cwd qw/abs_path/; use blib; @@ -18,7 +18,16 @@ throws_ok { new WebPAC::Normalize::XML( lookup_regex => 'foo' ) } qr/pair/, "lookup_regex without lookup"; throws_ok { new WebPAC::Normalize::XML( lookup => 'bar' ) } qr/pair/, "lookup without lookup_regex"; -ok(my $n = new WebPAC::Normalize::XML( debug => 0 ), "new"); +ok(my $n = new WebPAC::Normalize::XML( + debug => 1, + filter => { + regex => sub { + my ($val, $regex) = @_; + eval "\$val =~ $regex"; + return $val; + }, + }, +), "new"); throws_ok { $n->open() } qr/tag/, "open without tag"; throws_ok { $n->open( tag => 'isis' ) } qr/xml_file/, "open without xml_file"; @@ -131,5 +140,54 @@ ok(my $ds = $n->data_structure( $rec ), "data_structure"); -diag Dumper($rec, $ds); +#diag Dumper($rec, $ds); + +# fake load of our test normalisation data +$n->{tag} = 'isis'; + +#diag Dumper($n->{import_xml}->{indexer}); + + +$rec = { + '900' => [ { + 'a' => '1', + 'b' => '2', + 'c' => '3', + 'txt' => 'yap', + } ], +}; + +my $import = { + 'Tag' => { 'isis' => [ + { content => 'v900^a + v900^b = v900^c [txt]' }, + ] }, +}; + +sub parse_test($$$) { + my ($import,$rec,$r) = @_; + $n->{import_xml}->{indexer} = $import; + # erase internal cache (yak!) + delete($n->{tags_by_order}); + push @{$rec->{'000'}}, 42 unless ($rec->{'000'}); + diag "test normalisation of: ",Dumper($n->{import_xml}->{indexer}, $rec); + ok(my $ds = $n->data_structure( $rec ), "data_structure"); + diag Dumper($ds); + cmp_ok($ds->{Tag}->{display}->[0], 'eq', $r, "parse $r"); +} + +parse_test($import, $rec, '1 + 2 = 3 [yap]'); + +delete($rec->{'900'}->[0]->{'b'}); +parse_test($import, $rec, '1 = 3 [yap]'); + +$rec->{'900'}->[0]->{'b'} = 5; +$rec->{'900'}->[0]->{'c'} = 6; +parse_test($import, $rec, '1 + 5 = 6 [yap]'); + +delete($rec->{'900'}->[0]->{'c'}); +parse_test($import, $rec, '1 + 5'); + +$rec->{'900'}->[0]->{'txt'} = 'nope!'; +delete($rec->{'900'}->[0]->{'a'}); +parse_test($import, $rec, '5 [nope!]');