--- trunk/t/3-normalize-xml.t 2005/12/23 21:05:50 314 +++ trunk/t/3-normalize-xml.t 2006/01/07 18:23:27 352 @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::More tests => 76; +use Test::More tests => 84; use Test::Exception; use Cwd qw/abs_path/; use blib; @@ -13,13 +13,13 @@ ok(my $abs_path = abs_path($0), "abs_path"); $abs_path =~ s#/[^/]*$#/#; -diag "abs_path: $abs_path"; +#diag "abs_path: $abs_path"; 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 => 1, + debug => 0, filter => { regex => sub { my ($val, $regex) = @_; @@ -149,18 +149,17 @@ $rec = { - '900' => [ - { - 'a' => '1', - 'b' => '2', - 'c' => '3', - } - ], + '900' => [ { + 'a' => '1', + 'b' => '2', + 'c' => '3', + 'x' => 'yap', + } ], }; my $import = { 'Tag' => { 'isis' => [ - { content => 'v900^a + v900^b = v900^c' }, + { content => 'v900^a + v900^b = v900^c [v900^x]' }, ] }, }; @@ -169,11 +168,27 @@ $n->{import_xml}->{indexer} = $import; # erase internal cache (yak!) delete($n->{tags_by_order}); - push @{$rec->{'000'}}, 42; - diag "test normalisation of: ",Dumper($n->{import_xml}->{indexer}, $rec); + 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); + #diag Dumper($ds); cmp_ok($ds->{Tag}->{display}->[0], 'eq', $r, "parse $r"); } -parse_test($import, $rec, '1 + 2 = 3'); +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'}); +$rec->{'900'}->[0]->{'x'} = 'hmmm'; +parse_test($import, $rec, '1 + 5 [hmmm]'); + +$rec->{'900'}->[0]->{'x'} = 'nope!'; +delete($rec->{'900'}->[0]->{'a'}); +parse_test($import, $rec, '5 [nope!]'); +