skip empty results of hash_filter
[Biblio-Isis] / t / 002_isis.t
index fa8a709..72f0398 100755 (executable)
@@ -5,26 +5,33 @@ use blib;
 
 use Data::Dumper;
 
-use Test::More tests => 108;
+use Test::More tests => 110;
+use File::Spec;
 
-BEGIN { use_ok( 'IsisDB' ); }
+BEGIN { use_ok( 'Biblio::Isis' ); }
 
+my $debug = shift @ARGV;
 my $isis;
 
+my $path_winisis = File::Spec->catfile('data', 'winisis', 'BIBL');
+my $path_isismarc = File::Spec->catfile('data', 'isismarc', 'BIBL');
+
 sub test_data {
 
        my $args = {@_};
 
-       isa_ok ($isis, 'IsisDB');
+       isa_ok ($isis, 'Biblio::Isis');
 
-       cmp_ok($isis->{maxmfn}, '==', 5, "maxmfn set to 5");
+       cmp_ok($isis->count, '==', 5, "count is 5");
 
        # test .CNT data
 
        SKIP: {
                skip "no CNT file for this database", 5 unless $isis->{cnt_file};
 
-               $isis->read_cnt;
+               ok(my $isis_cnt = $isis->read_cnt, "read_cnt");
+
+               cmp_ok(scalar keys %{$isis_cnt}, '==', 2, "returns 2 elements");
 
                my $cnt = {
                        '1' => {
@@ -53,7 +60,7 @@ sub test_data {
 
                foreach my $c (keys %{$cnt}) {
                        foreach my $kn (keys %{$cnt->{$c}}) {
-                               cmp_ok($isis->{cnt}->{$c}->{$kn}, '==', $cnt->{$c}->{$kn}, "cnt $c $kn same");
+                               cmp_ok($isis_cnt->{$c}->{$kn}, '==', $cnt->{$c}->{$kn}, "cnt $c $kn same");
                        }
                }
        }
@@ -90,7 +97,7 @@ sub test_data {
                '200' => [ '1#^aPsychology^fCamille B. Wortman, Elizabeth F. Loftus, Mary E. Marshal' ],
        } ];
                
-       foreach my $mfn (1 .. $isis->{'maxmfn'}) {
+       foreach my $mfn (1 .. $isis->count) {
                my $rec;
                ok($rec = $isis->fetch($mfn), "fetch $mfn");
 
@@ -111,7 +118,7 @@ sub test_data {
 
                skip "no Digest::MD5 module", 5 if ($@);
 
-               foreach my $mfn (1 .. $isis->{'maxmfn'}) {
+               foreach my $mfn (1 .. $isis->count) {
                        my $md5 = md5_hex($isis->to_ascii($mfn));
                        cmp_ok($md5, 'eq', $args->{md5_ascii}[$mfn - 1], "md5 $mfn");
                }
@@ -119,9 +126,10 @@ sub test_data {
 
 }
 
-$isis = IsisDB->new (
-       isisdb => './data/winisis/BIBL',
+$isis = Biblio::Isis->new (
+       isisdb => $path_winisis,
        include_deleted => 1,
+       debug => $debug,
 );
 
 print Dumper($isis);
@@ -137,8 +145,8 @@ test_data(
        ) ],
 );
 
-$isis = IsisDB->new (
-       isisdb => './data/isismarc/BIBL',
+$isis = Biblio::Isis->new (
+       isisdb => $path_isismarc,
        include_deleted => 1,
 );
 
@@ -154,16 +162,17 @@ test_data(
 
 # check logically deleted
 
-$isis = IsisDB->new (
-       isisdb => './data/winisis/BIBL',
+$isis = Biblio::Isis->new (
+       isisdb => $path_winisis,
        include_deleted => 1,
 );
 
 ok($isis->fetch(3), "deleted found");
 cmp_ok($isis->{deleted}, '==', 3, "MFN 3 is deleted");
 
-$isis = IsisDB->new (
-       isisdb => './data/winisis/BIBL',
+$isis = Biblio::Isis->new (
+       isisdb => $path_winisis,
+       debug => $debug,
 );
 
 ok(! $isis->fetch(3), "deleted not found");