3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Test::More tests => 20; |
use Test::More tests => 40; |
7 |
use Test::Exception; |
use Test::Exception; |
|
use Data::Dumper; |
|
8 |
|
|
9 |
BEGIN { use_ok( 'MARC::Fast' ); } |
BEGIN { |
10 |
|
use_ok( 'MARC::Fast' ); |
11 |
|
} |
12 |
|
|
13 |
|
my $debug = shift @ARGV; |
14 |
|
if ( $debug ) { |
15 |
|
eval { require Data::Dump; }; |
16 |
|
$debug = 0 if ($@); |
17 |
|
} |
18 |
|
|
19 |
my $marc; |
my $marc; |
20 |
my %param; |
my %param; |
25 |
|
|
26 |
throws_ok { $marc = MARC::Fast->new(%param); } qr/foo.bar/, "marcdb exist"; |
throws_ok { $marc = MARC::Fast->new(%param); } qr/foo.bar/, "marcdb exist"; |
27 |
|
|
28 |
$param{marcdb} = '../unimarc.iso'; |
$param{marcdb} = 'data/unimarc.iso'; |
29 |
|
|
30 |
ok($marc = MARC::Fast->new(%param), "new"); |
SKIP: { |
31 |
|
skip "no $param{marcdb} test file ", 37 unless (-e $param{marcdb}); |
32 |
|
|
33 |
isa_ok ($marc, 'MARC::Fast'); |
ok($marc = MARC::Fast->new(%param), "new"); |
34 |
|
|
35 |
cmp_ok($marc->count, '==', scalar @{$marc->{leaders}}, "count == leaders"); |
isa_ok ($marc, 'MARC::Fast'); |
|
cmp_ok($marc->count, '==', scalar @{$marc->{fh_offset}}, "count == fh_offset"); |
|
36 |
|
|
37 |
ok(! $marc->fetch(0), "fetch 0"); |
#diag Dumper($marc); |
|
ok($marc->fetch($marc->count), "fetch max:".$marc->count); |
|
|
ok(! $marc->fetch($marc->count + 1), "fetch max+1:".($marc->count+1)); |
|
38 |
|
|
39 |
foreach (1 .. 10) { |
cmp_ok($marc->count, '==', scalar @{$marc->{leaders}}, "count == leaders"); |
40 |
ok($marc->fetch($_), "fetch $_"); |
cmp_ok($marc->count, '==', scalar @{$marc->{fh_offset}}, "count == fh_offset"); |
|
} |
|
41 |
|
|
42 |
|
ok(! $marc->fetch(0), "fetch 0"); |
43 |
|
ok($marc->fetch($marc->count), "fetch max:".$marc->count); |
44 |
|
ok(! $marc->fetch($marc->count + 1), "fetch max+1:".($marc->count+1)); |
45 |
|
|
46 |
|
foreach (1 .. 10) { |
47 |
|
ok($marc->fetch($_), "fetch $_"); |
48 |
|
|
49 |
|
ok(my $hash = $marc->to_hash($_), "to_hash $_"); |
50 |
|
diag "to_hash($_) = ",Data::Dump::dump($hash) if ($debug); |
51 |
|
ok(my $ascii = $marc->to_ascii($_), "to_ascii $_"); |
52 |
|
diag "to_ascii($_) ::\n$ascii" if ($debug); |
53 |
|
} |
54 |
|
} |