X-Git-Url: http://git.rot13.org/?p=MARC-Fast;a=blobdiff_plain;f=t%2F001_marc.t;h=ddbee94802784c3cecc0ba554fc4b72fcbe2e0d5;hp=02d75af8981f70e4bd2a8fc9ddca160097065b7f;hb=5fc18887422d2dd62c716b73d81a226f3a295e5b;hpb=8d434a1c9a1414e59e7a802cae41877bef3307e4 diff --git a/t/001_marc.t b/t/001_marc.t index 02d75af..ddbee94 100755 --- a/t/001_marc.t +++ b/t/001_marc.t @@ -3,14 +3,18 @@ use strict; use blib; -use Test::More tests => 40; +use Test::More tests => 63; use Test::Exception; use Data::Dump qw/dump/; -BEGIN { use_ok( 'MARC::Fast' ); } +BEGIN { + use_ok( 'MARC::Fast' ); +} my $debug = shift @ARGV; +my $marc_file = 't/camel.usmarc'; + my $marc; my %param; @@ -20,30 +24,42 @@ $param{marcdb} = '/foo/bar/file'; throws_ok { $marc = MARC::Fast->new(%param); } qr/foo.bar/, "marcdb exist"; -$param{marcdb} = 'data/unimarc.iso'; +$param{marcdb} = $marc_file if -e $marc_file; SKIP: { skip "no $param{marcdb} test file ", 37 unless (-e $param{marcdb}); + diag "marc file: $marc_file"; + ok($marc = MARC::Fast->new(%param), "new"); isa_ok ($marc, 'MARC::Fast'); #diag Dumper($marc); - cmp_ok($marc->count, '==', scalar @{$marc->{leaders}}, "count == leaders"); + 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->fetch($_), "fetch($_)"); + + ok($marc->last_leader, "last_leader $_"); - ok(my $hash = $marc->to_hash($_), "to_hash $_"); - diag "to_hash($_) = ",dump($hash) if ($debug); - ok(my $ascii = $marc->to_ascii($_), "to_ascii $_"); + ok(my $hash = $marc->to_hash($_), "to_hash($_)"); + diag "to_hash($_) = ",Data::Dump::dump($hash) if ($debug); + + ok(my $hash_sf = $marc->to_hash($_, include_subfields => 1), "to_hash($_,include_subfields)"); + diag "to_hash($_, include_subfields => 1) = ",Data::Dump::dump($hash_sf) 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"); }