File: 001_marc.t

package info (click to toggle)
libmarc-fast-perl 0.12-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 164 kB
  • sloc: perl: 327; makefile: 2
file content (66 lines) | stat: -rwxr-xr-x 1,644 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl -w

use strict;
use blib;

use Test::More tests => 63;
use Data::Dump qw/dump/;

BEGIN {
	use_ok( 'MARC::Fast' );
}

my $debug = shift @ARGV;

my $marc_file = 't/camel.usmarc';

my $marc;
my %param;

eval { $marc = MARC::Fast->new(%param) };
ok( $@ =~ /marcdb/, "marcdb parametar" );

$param{marcdb} = '/foo/bar/file';

eval { $marc = MARC::Fast->new(%param) };
ok( $@ =~ /foo.bar/, "marcdb exist" );

$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->{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->last_leader, "last_leader $_");

		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");
}