| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use Test::Exception; |
| 7 |
use Catmandu::Importer::MARC; |
| 8 |
use utf8; |
| 9 |
|
| 10 |
my $pkg; |
| 11 |
|
| 12 |
BEGIN { |
| 13 |
$pkg = 'Catmandu::Importer::MARC::ALEPHSEQ'; |
| 14 |
use_ok $pkg; |
| 15 |
} |
| 16 |
|
| 17 |
require_ok $pkg; |
| 18 |
|
| 19 |
my $record =<<'EOF'; |
| 20 |
000000002 FMT L BK |
| 21 |
000000002 LDR L 00000nam^a2200301^i^4500 |
| 22 |
000000002 001 L 000000002 |
| 23 |
000000002 008 L 050601s1921^^^^xx^||||||||||||||^||dut^^ |
| 24 |
000000002 24510 L $$aCatmandu Test |
| 25 |
000000002 650 0 L $$aPerl |
| 26 |
000000002 650 0 L $$aMARC$$aMARC2 |
| 27 |
000000002 650 0 L $$a加德滿都 |
| 28 |
EOF |
| 29 |
|
| 30 |
my $expected = { |
| 31 |
_id => '000000002', |
| 32 |
record => [ |
| 33 |
[ 'FMT', ' ', ' ' , '_', 'BK' ] , |
| 34 |
[ 'LDR', ' ', ' ' , '_', '00000nam a2200301 i 4500' ] , |
| 35 |
[ '001', ' ', ' ' , '_', '000000002' ] , |
| 36 |
[ '008', ' ', ' ' , '_', '050601s1921 xx |||||||||||||| ||dut ' ], |
| 37 |
[ '245', '1', '0' , 'a', 'Catmandu Test' ] , |
| 38 |
[ '650', ' ', '0' , 'a', 'Perl' ] , |
| 39 |
[ '650', ' ', '0' , 'a', 'MARC' , 'a' , 'MARC2' ] , |
| 40 |
[ '650', ' ', '0' , 'a', '加德滿都' ] , |
| 41 |
] |
| 42 |
}; |
| 43 |
|
| 44 |
note("inline pasing"); |
| 45 |
{ |
| 46 |
my $importer = Catmandu::Importer::MARC->new( file => \$record, type => "ALEPHSEQ" ); |
| 47 |
|
| 48 |
ok $importer , 'got an MARC/ALEPHSEQ importer'; |
| 49 |
|
| 50 |
my $result = $importer->first; |
| 51 |
|
| 52 |
ok $result , 'got a record'; |
| 53 |
|
| 54 |
is_deeply $result , $expected , 'got the expected result'; |
| 55 |
} |
| 56 |
|
| 57 |
note("file pasing"); |
| 58 |
{ |
| 59 |
my $importer = Catmandu::Importer::MARC->new( file => 't/rug01.aleph', type => "ALEPHSEQ" ); |
| 60 |
|
| 61 |
ok $importer , 'got an MARC/ALEPHSEQ importer'; |
| 62 |
|
| 63 |
my $results = $importer->to_array; |
| 64 |
|
| 65 |
ok @$results == 2 , 'got two records'; |
| 66 |
|
| 67 |
is_deeply $results->[0] , $expected , 'got the expected result'; |
| 68 |
} |
| 69 |
|
| 70 |
done_testing; |