--- trunk/t/3-normalize-xml.t 2005/07/16 22:57:26 12 +++ trunk/t/3-normalize-xml.t 2005/11/19 23:48:24 70 @@ -1,10 +1,11 @@ #!/usr/bin/perl -w -use Test::More tests => 6; +use Test::More tests => 74; use Test::Exception; use Cwd qw/abs_path/; use blib; use strict; +use Data::Dumper; BEGIN { use_ok( 'WebPAC::Normalize::XML' ); @@ -14,13 +15,121 @@ $abs_path =~ s#/[^/]*$#/#; diag "abs_path: $abs_path"; -throws_ok { new WebPAC::Normalize::XML() } qr/tag/, "new without tag"; -throws_ok { new WebPAC::Normalize::XML( tag => 'isis' ) } qr/xml_file/, "new without xml_file"; -throws_ok { new WebPAC::Normalize::XML( tag => 'isis', xml_file => 'foo' ) } qr/file.*doesn't exist/, "new with invalid xml_file"; -ok(my $isis = new WebPAC::Normalize::XML( +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"); + +throws_ok { $n->open() } qr/tag/, "open without tag"; +throws_ok { $n->open( tag => 'isis' ) } qr/xml_file/, "open without xml_file"; +throws_ok { $n->open( tag => 'isis', xml_file => '/foo/bar/baz' ) } qr/file.*doesn't exist/, "open with invalid xml_file"; +ok( $n->open( tag => 'isis', - xml_file => "$abs_path../conf/normalize/isis.xml", - debug => 1, -), "new"); + xml_file => "$abs_path/data/normalize.xml", +), "open"); + +my $rec = { + '675' => [ + { + 'a' => '159.9' + } + ], + '210' => [ + { + 'c' => 'New York University press', + 'a' => 'New York', + 'd' => 'cop. 1988' + } + ], + '700' => [ + { + 'a' => 'Haynal', + 'b' => 'André' + } + ], + '801' => [ + 'FFZG' + ], + '991' => [ + '8302' + ], + '000' => [ + 1 + ], + '702' => [ + { + 'a' => 'Holder', + 'b' => 'Elizabeth' + } + ], + '215' => [ + { + 'c' => 'ilustr', + 'a' => 'xix, 202 str', + 'd' => '23cm' + } + ], + '990' => [ + '2140', + '88', + 'HAY' + ], + '200' => [ + { + 'e' => 'from Freud and Ferenczi to Michael balint', + 'a' => 'Controversies in psychoanalytic method', + 'g' => 'translated by Elizabeth Holder on the basisi of a first draft by Archie Hooton ; with a preface by Daniel N. Stern', + 'f' => 'by André E. Haynal' + } + ], + '610' => [ + 'povijest psihoanalize' + ], + '994' => [ + { + 'c' => '', + 'a' => 'PS', + 'b' => 'MG' + } + ], + '320' => [ + 'Kazalo' + ], + '101' => [ + 'ENG' + ], + '686' => [ + '2140' + ], + '300' => [ + 'Prijevod djela: ' + ] +}; + +foreach my $fld (keys %$rec) { + my $r = 0; + foreach my $item ($rec->{$fld}) { + if (ref($item) eq 'HASH') { + foreach my $sf (keys %$item) { + my $found = 0; + ok($n->get_data(\$rec, $fld, $sf, $r, \$found), "v${fld}^${sf}"); + ok($found, "found"); + } + my $found = 0; + ok(! $n->get_data(\$rec, $fld, 'x', $r, \$found), "no v${fld}^x"); + ok(! $found, "not found"); + } else { + my $found = 0; + ok($n->get_data(\$rec, $fld, '', $r, \$found), "v${fld}"); + ok($found, "found"); + } + } + my $found = 0; + ok(! $n->get_data(\$rec, '999', '', $r, \$found), "no v${fld}"); + ok(! $found, "not found"); +} + +ok(my $ds = $n->data_structure( $rec ), "data_structure"); +diag Dumper($rec, $ds);