Codebase list libcatmandu-marc-perl / 11a2931
Fixing undef 'indicators' for leaders Patrick Hochstenbach 6 years ago
2 changed file(s) with 38 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
2222 return unless eval { $record->isa('MARC::Record') };
2323 my @result = ();
2424
25 push @result , [ 'LDR' , undef, undef, '_' , $record->leader ];
25 push @result , [ 'LDR' , ' ', ' ' , '_' , $record->leader ];
2626
2727 for my $field ($record->fields()) {
2828 my $tag = $field->tag;
29 my $ind1 = $field->indicator(1);
30 my $ind2 = $field->indicator(2);
29 my $ind1 = $field->indicator(1) // ' ';
30 my $ind2 = $field->indicator(2) // ' ';
3131
3232 my @sf = ();
3333
44 use Test::More;
55 use Test::Exception;
66 use Catmandu::Exporter::MARC;
7 use Catmandu::Importer::MARC;
8 use utf8;
79
810 my $pkg;
911
1618
1719 my $marciso = undef;
1820
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 };
2032
21 ok $exporter , 'got an MARC/ISO exporter';
33 note("export marc");
34 {
35 my $exporter = Catmandu::Exporter::MARC->new(file => \$marciso, type=> 'ISO');
2236
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';
3938
40 ok $exporter->commit , 'commit';
39 ok $exporter->add($record) , 'add';
4140
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 }
4358
4459 done_testing;