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