X-Git-Url: http://git.rot13.org/?p=MARC-Fast;a=blobdiff_plain;f=t%2F001_marc.t;h=990d0780fc6bfcffd5525a78ffaf50cfabb5f6b1;hp=547d5cb98e7a488d3cf26448d464706414a4b77c;hb=12f18ad14a52dc83e3449d908fb0678e16dabb49;hpb=5c5233ec1192462b4f0e5d30ba274f1b09cc69fc diff --git a/t/001_marc.t b/t/001_marc.t index 547d5cb..990d078 100755 --- a/t/001_marc.t +++ b/t/001_marc.t @@ -3,11 +3,18 @@ use strict; use blib; -use Test::More tests => 20; +use Test::More tests => 53; use Test::Exception; -use Data::Dumper; -BEGIN { use_ok( 'MARC::Fast' ); } +BEGIN { + use_ok( 'MARC::Fast' ); +} + +my $debug = shift @ARGV; +if ( $debug ) { + eval { require Data::Dump; }; + $debug = 0 if ($@); +} my $marc; my %param; @@ -18,20 +25,36 @@ $param{marcdb} = '/foo/bar/file'; throws_ok { $marc = MARC::Fast->new(%param); } qr/foo.bar/, "marcdb exist"; -$param{marcdb} = '../unimarc.iso'; +$param{marcdb} = 'data/unimarc.iso'; -ok($marc = MARC::Fast->new(%param), "new"); +SKIP: { + skip "no $param{marcdb} test file ", 37 unless (-e $param{marcdb}); -isa_ok ($marc, 'MARC::Fast'); + ok($marc = MARC::Fast->new(%param), "new"); -cmp_ok($marc->count, '==', scalar @{$marc->{leaders}}, "count == leaders"); -cmp_ok($marc->count, '==', scalar @{$marc->{fh_offset}}, "count == fh_offset"); + isa_ok ($marc, 'MARC::Fast'); -ok(! $marc->fetch(0), "fetch 0"); -ok($marc->fetch($marc->count), "fetch max:".$marc->count); -ok(! $marc->fetch($marc->count + 1), "fetch max+1:".($marc->count+1)); + #diag Dumper($marc); -foreach (1 .. 10) { - ok($marc->fetch($_), "fetch $_"); -} + cmp_ok($marc->count, '==', scalar @{$marc->{leader}}, "count == leader"); + cmp_ok($marc->count, '==', scalar @{$marc->{fh_offset}}, "count == fh_offset"); + + ok(! $marc->fetch(0), "fetch 0"); + ok(! $marc->last_leader, "no last_leader"); + ok($marc->fetch($marc->count), "fetch max:".$marc->count); + ok(! $marc->fetch($marc->count + 1), "fetch max+1:".($marc->count+1)); + foreach (1 .. 10) { + ok($marc->fetch($_), "fetch $_"); + + ok($marc->last_leader, "last_leader $_"); + + ok(my $hash = $marc->to_hash($_), "to_hash $_"); + diag "to_hash($_) = ",Data::Dump::dump($hash) if ($debug); + ok(my $ascii = $marc->to_ascii($_), "to_ascii $_"); + diag "to_ascii($_) ::\n$ascii" if ($debug); + } + + ok(! $marc->fetch(0), "fetch 0 again"); + ok(! $marc->last_leader, "no last_leader"); +}