| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use Test::Exception; |
| 7 |
use MARC::File::USMARC; |
| 8 |
use Catmandu::Importer::MARC; |
| 9 |
|
| 10 |
my $pkg; |
| 11 |
|
| 12 |
BEGIN { |
| 13 |
$pkg = 'Catmandu::Importer::MARC::Record'; |
| 14 |
use_ok $pkg; |
| 15 |
} |
| 16 |
|
| 17 |
require_ok $pkg; |
| 18 |
|
| 19 |
my $file = MARC::File::USMARC->in('t/camel.mrc'); |
| 20 |
my @marc_objects; |
| 21 |
while ( my $marc = $file->next() ) { |
| 22 |
push( @marc_objects, $marc ); |
| 23 |
} |
| 24 |
$file->close(); |
| 25 |
undef $file; |
| 26 |
|
| 27 |
my $importer = Catmandu::Importer::MARC->new(type => 'Record' , records => \@marc_objects ); |
| 28 |
|
| 29 |
ok $importer , 'got an MARC/Record importer'; |
| 30 |
|
| 31 |
my $records = $importer->to_array(); |
| 32 |
|
| 33 |
ok( @$records == 10, 'got all records' ); |
| 34 |
ok( $records->[0]->{'_id'} eq 'fol05731351 ', 'got _id' ); |
| 35 |
ok( $records->[0]->{'record'}->[1][-1] eq 'fol05731351 ', 'got subfield' ); |
| 36 |
ok( $records->[0]->{'_id'} eq $records->[0]->{'record'}->[1][-1], |
| 37 |
'_id matches record id' ); |
| 38 |
|
| 39 |
done_testing; |