1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use strict; |
4 |
use blib; |
5 |
|
6 |
use Test::More tests => 20; |
7 |
use Test::Exception; |
8 |
use Data::Dumper; |
9 |
|
10 |
BEGIN { use_ok( 'MARC::Fast' ); } |
11 |
|
12 |
my $marc; |
13 |
my %param; |
14 |
|
15 |
throws_ok { $marc = MARC::Fast->new(%param); } qr/marcdb/, "marcdb parametar"; |
16 |
|
17 |
$param{marcdb} = '/foo/bar/file'; |
18 |
|
19 |
throws_ok { $marc = MARC::Fast->new(%param); } qr/foo.bar/, "marcdb exist"; |
20 |
|
21 |
$param{marcdb} = 'data/unimarc.iso'; |
22 |
|
23 |
SKIP: { |
24 |
skip "no $param{marcdb} test file ", 17 unless (-e $param{marcdb}); |
25 |
|
26 |
ok($marc = MARC::Fast->new(%param), "new"); |
27 |
|
28 |
isa_ok ($marc, 'MARC::Fast'); |
29 |
|
30 |
#diag Dumper($marc); |
31 |
|
32 |
cmp_ok($marc->count, '==', scalar @{$marc->{leaders}}, "count == leaders"); |
33 |
cmp_ok($marc->count, '==', scalar @{$marc->{fh_offset}}, "count == fh_offset"); |
34 |
|
35 |
ok(! $marc->fetch(0), "fetch 0"); |
36 |
ok($marc->fetch($marc->count), "fetch max:".$marc->count); |
37 |
ok(! $marc->fetch($marc->count + 1), "fetch max+1:".($marc->count+1)); |
38 |
|
39 |
foreach (1 .. 10) { |
40 |
ok($marc->fetch($_), "fetch $_"); |
41 |
|
42 |
ok(my $hash = $marc->to_hash($_), "to_hash $_"); |
43 |
diag "$_ :: ",Dumper($hash); |
44 |
} |
45 |
} |