| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use Test::Exception; |
| 7 |
use Catmandu::Exporter::MARC; |
| 8 |
use utf8; |
| 9 |
|
| 10 |
my $pkg; |
| 11 |
|
| 12 |
BEGIN { |
| 13 |
$pkg = 'Catmandu::Exporter::MARC::ALEPHSEQ'; |
| 14 |
use_ok $pkg; |
| 15 |
} |
| 16 |
|
| 17 |
require_ok $pkg; |
| 18 |
|
| 19 |
note("catmandu marc export"); |
| 20 |
{ |
| 21 |
my $alephseq = undef; |
| 22 |
|
| 23 |
my $record = { |
| 24 |
_id => '000000002', |
| 25 |
record => [ |
| 26 |
[ 'FMT', ' ', ' ' , '_', 'BK' ] , |
| 27 |
[ 'LDR', ' ', ' ' , '_', '00000nam a2200301 i 4500' ] , |
| 28 |
[ '001', ' ', ' ' , '_', '000000002' ] , |
| 29 |
[ '008', ' ', ' ' , '_', '050601s1921 xx |||||||||||||| ||dut ' ], |
| 30 |
[ '245', '1', '0' , 'a', 'Catmandu Test' ] , |
| 31 |
[ '650', ' ', '0' , 'a', 'Perl' ] , |
| 32 |
[ '650', ' ', '0' , 'a', 'MARC' , '<' , 'MARC2' ] , |
| 33 |
[ '650', ' ', '0' , 'a', '加德滿都' ] , |
| 34 |
] |
| 35 |
}; |
| 36 |
|
| 37 |
my $expected =<<'EOF'; |
| 38 |
000000002 FMT L BK |
| 39 |
000000002 LDR L 00000nam^a2200301^i^4500 |
| 40 |
000000002 001 L 000000002 |
| 41 |
000000002 008 L 050601s1921^^^^xx^||||||||||||||^||dut^^ |
| 42 |
000000002 24510 L $$aCatmandu Test |
| 43 |
000000002 650 0 L $$aPerl |
| 44 |
000000002 650 0 L $$aMARC$$<MARC2 |
| 45 |
000000002 650 0 L $$a加德滿都 |
| 46 |
EOF |
| 47 |
|
| 48 |
my $exporter = Catmandu::Exporter::MARC->new(file => \$alephseq, type=> 'ALEPHSEQ' , skip_empty_subfields => 1); |
| 49 |
|
| 50 |
ok $exporter , 'got an MARC/ALEPHSEQ exporter'; |
| 51 |
|
| 52 |
ok $exporter->add($record) , 'add a record'; |
| 53 |
|
| 54 |
ok $exporter->commit , 'commit'; |
| 55 |
|
| 56 |
is_deeply $alephseq , $expected , 'got expected results'; |
| 57 |
} |
| 58 |
|
| 59 |
note("marc-in-json export"); |
| 60 |
{ |
| 61 |
my $alephseq ; |
| 62 |
|
| 63 |
|
| 64 |
my $exporter = Catmandu::Exporter::MARC->new( |
| 65 |
file => \$alephseq, |
| 66 |
type=> 'ALEPHSEQ', |
| 67 |
record_format => 'MARC-in-JSON', |
| 68 |
skip_empty_subfields => 1 |
| 69 |
); |
| 70 |
|
| 71 |
ok($exporter, "create exporter ALEPHSEQ for MARC-in-JSON"); |
| 72 |
|
| 73 |
my $record = { |
| 74 |
_id => '000000002', |
| 75 |
leader => "00000nam a2200301 i 4500" , |
| 76 |
fields => [ |
| 77 |
{ '001' => '000000002' } , |
| 78 |
{ '245' => { |
| 79 |
ind1 => '1' , |
| 80 |
ind2 => '0' , |
| 81 |
subfields => [ |
| 82 |
{ a => 'Catmandu Test'} |
| 83 |
] |
| 84 |
} |
| 85 |
} , |
| 86 |
{ '650' => { |
| 87 |
ind1 => ' ' , |
| 88 |
ind2 => '0' , |
| 89 |
subfields => [ |
| 90 |
{ a => 'Perl'} |
| 91 |
] |
| 92 |
} |
| 93 |
} , |
| 94 |
{ '650' => { |
| 95 |
ind1 => ' ' , |
| 96 |
ind2 => '0' , |
| 97 |
subfields => [ |
| 98 |
{ a => 'MARC'} , |
| 99 |
{ '<' => 'MARC2'} |
| 100 |
] |
| 101 |
} |
| 102 |
} , |
| 103 |
{ '650' => { |
| 104 |
ind1 => ' ' , |
| 105 |
ind2 => '0' , |
| 106 |
subfields => [ |
| 107 |
{ a => '加德滿都'} |
| 108 |
] |
| 109 |
} |
| 110 |
} , |
| 111 |
] |
| 112 |
}; |
| 113 |
|
| 114 |
my $expected =<<'EOF'; |
| 115 |
000000002 FMT L BK |
| 116 |
000000002 LDR L 00000nam^a2200301^i^4500 |
| 117 |
000000002 001 L 000000002 |
| 118 |
000000002 24510 L $$aCatmandu Test |
| 119 |
000000002 650 0 L $$aPerl |
| 120 |
000000002 650 0 L $$aMARC$$<MARC2 |
| 121 |
000000002 650 0 L $$a加德滿都 |
| 122 |
EOF |
| 123 |
|
| 124 |
ok $exporter->add($record), 'add record'; |
| 125 |
|
| 126 |
ok $exporter->commit() , 'commit'; |
| 127 |
|
| 128 |
is_deeply $alephseq , $expected , 'got expected results'; |
| 129 |
} |
| 130 |
|
| 131 |
done_testing; |