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