| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use Test::Exception; |
| 7 |
use Catmandu::Exporter::MARC; |
| 8 |
use Catmandu::Importer::MARC; |
| 9 |
use utf8; |
| 10 |
|
| 11 |
my $pkg; |
| 12 |
|
| 13 |
BEGIN { |
| 14 |
$pkg = 'Catmandu::Exporter::MARC::ISO'; |
| 15 |
use_ok $pkg; |
| 16 |
} |
| 17 |
|
| 18 |
require_ok $pkg; |
| 19 |
|
| 20 |
my $marciso = undef; |
| 21 |
|
| 22 |
my $record = { |
| 23 |
_id => '000000002', |
| 24 |
record => [ |
| 25 |
[ 'LDR', ' ', ' ' , '_', '00209nam a2200097 i 4500' ] , |
| 26 |
[ '001', ' ', ' ' , '_', '000000002' ] , |
| 27 |
[ '008', ' ', ' ' , '_', '050601s1921 xx |||||||||||||| ||dut ' ], |
| 28 |
[ '245', '1', '0' , 'a', 'Catmandu Test' ] , |
| 29 |
[ '650', ' ', '0' , 'a', 'Perl' ] , |
| 30 |
[ '650', ' ', '0' , 'a', 'MARC' , 'a' , 'MARC2' ] , |
| 31 |
[ '650', ' ', '0' , 'a', '加德滿都' ] , |
| 32 |
] |
| 33 |
}; |
| 34 |
|
| 35 |
note("export marc"); |
| 36 |
{ |
| 37 |
my $exporter = Catmandu::Exporter::MARC->new(file => \$marciso, type=> 'ISO'); |
| 38 |
|
| 39 |
ok $exporter , 'got a MARC/ISO exporter'; |
| 40 |
|
| 41 |
ok $exporter->add($record) , 'add'; |
| 42 |
|
| 43 |
ok $exporter->commit , 'commit'; |
| 44 |
|
| 45 |
ok length($marciso) >= 127 , 'got iso'; |
| 46 |
} |
| 47 |
|
| 48 |
note("parse the results"); |
| 49 |
{ |
| 50 |
my $importer = Catmandu::Importer::MARC->new(file => \$marciso , type => 'ISO'); |
| 51 |
|
| 52 |
ok $importer , 'got a MARC/ISO importer'; |
| 53 |
|
| 54 |
my $result = $importer->first; |
| 55 |
|
| 56 |
ok $result , 'got a result'; |
| 57 |
|
| 58 |
is_deeply $result , $record , 'got the expected result'; |
| 59 |
} |
| 60 |
|
| 61 |
done_testing; |