4 | 4 |
use Test::More;
|
5 | 5 |
use Test::Exception;
|
6 | 6 |
use Catmandu::Exporter::MARC;
|
|
7 |
use Catmandu::Importer::MARC;
|
|
8 |
use utf8;
|
7 | 9 |
|
8 | 10 |
my $pkg;
|
9 | 11 |
|
|
16 | 18 |
|
17 | 19 |
my $marciso = undef;
|
18 | 20 |
|
19 | |
my $exporter = Catmandu::Exporter::MARC->new(file => \$marciso, type=> 'ISO');
|
|
21 |
my $record = {
|
|
22 |
_id => '000000002',
|
|
23 |
record => [
|
|
24 |
[ 'LDR', ' ', ' ' , '_', '00156nam a2200085 i 4500' ] ,
|
|
25 |
[ '001', ' ', ' ' , '_', '000000002' ] ,
|
|
26 |
[ '245', '1', '0' , 'a', 'Catmandu Test' ] ,
|
|
27 |
[ '650', ' ', '0' , 'a', 'Perl' ] ,
|
|
28 |
[ '650', ' ', '0' , 'a', 'MARC' , 'a' , 'MARC2' ] ,
|
|
29 |
[ '650', ' ', '0' , 'a', '加德滿都' ] ,
|
|
30 |
]
|
|
31 |
};
|
20 | 32 |
|
21 | |
ok $exporter , 'got an MARC/ISO exporter';
|
|
33 |
note("export marc");
|
|
34 |
{
|
|
35 |
my $exporter = Catmandu::Exporter::MARC->new(file => \$marciso, type=> 'ISO');
|
22 | 36 |
|
23 | |
ok $exporter->add({
|
24 | |
_id => '1' ,
|
25 | |
record => [
|
26 | |
['FMT', undef, undef, '_', 'BK'],
|
27 | |
['001', undef, undef, '_', 'rec001'],
|
28 | |
['100', ' ', ' ', 'a', 'Davis, Miles' , 'c' , 'Test'],
|
29 | |
['245', ' ', ' ',
|
30 | |
'a', 'Sketches in Blue' ,
|
31 | |
],
|
32 | |
['500', ' ', ' ', 'a', undef],
|
33 | |
['501', ' ', ' ' ],
|
34 | |
['502', ' ', ' ', 'a', undef, 'b' , 'ok'],
|
35 | |
['503', ' ', ' ', 'a', ''],
|
36 | |
['CAT', ' ', ' ', 'a', 'test'],
|
37 | |
]
|
38 | |
}) , 'add';
|
|
37 |
ok $exporter , 'got a MARC/ISO exporter';
|
39 | 38 |
|
40 | |
ok $exporter->commit , 'commit';
|
|
39 |
ok $exporter->add($record) , 'add';
|
41 | 40 |
|
42 | |
ok length($marciso) >= 127 , 'got iso';
|
|
41 |
ok $exporter->commit , 'commit';
|
|
42 |
|
|
43 |
ok length($marciso) >= 127 , 'got iso';
|
|
44 |
}
|
|
45 |
|
|
46 |
note("parse the results");
|
|
47 |
{
|
|
48 |
my $importer = Catmandu::Importer::MARC->new(file => \$marciso , type => 'ISO');
|
|
49 |
|
|
50 |
ok $importer , 'got a MARC/ISO importer';
|
|
51 |
|
|
52 |
my $result = $importer->first;
|
|
53 |
|
|
54 |
ok $result , 'got a result';
|
|
55 |
|
|
56 |
is_deeply $result , $record , 'got the expected result';
|
|
57 |
}
|
43 | 58 |
|
44 | 59 |
done_testing;
|