Debian Codegraph @

t/Catmandu/Exporter/MARC/Line.t

raw
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
10 my $pkg;
11
12 BEGIN {
13 $pkg = 'Catmandu::Exporter::MARC::Line';
14 use_ok $pkg;
15 }
16
17 require_ok $pkg;
18
19 my $marcline = undef;
20
21 note('Exporting to MARC/Line');
22 {
23 my $exporter = Catmandu::Exporter::MARC->new(file => \$marcline, type=> 'Line');
24
25 ok $exporter , 'got an MARC/Line exporter';
26
27 ok $exporter->add({
28 '_id' => '987874829',
29 'record' => [
30 [ 'LDR', ' ', ' ', '_', '00251nas a2200121 c 4500' ],
31 [ '001', ' ', ' ', '_', '987874829' ],
32 [ '007', ' ', ' ', '_', 'cr||||||||||||' ],
33 [ '022', ' ', ' ', 'a', '1940-5758' ],
34 [ '041', ' ', ' ', 'a', 'eng' ],
35 [ 245, '0', '0', 'a', 'Code4Lib journal', 'b', 'C4LJ' ],
36 [ 246, '3', ' ', 'a', 'C4LJ' ],
37 [ 362, '0', ' ', 'a', '1.2007 -' ],
38 [ 856, '4', ' ', 'u', 'http://journal.code4lib.org/' ]
39 ]}) , 'add';
40
41 ok $exporter->commit , 'commit';
42
43 my $expected = <<'EOF';
44 00251nas a2200121 c 4500
45 001 987874829
46 007 cr||||||||||||
47 022 $a 1940-5758
48 041 $a eng
49 245 00 $a Code4Lib journal $b C4LJ
50 246 3 $a C4LJ
51 362 0 $a 1.2007 -
52 856 4 $u http://journal.code4lib.org/
53
54 EOF
55
56
57 is $marcline, $expected, 'got the expected result';
58
59 }
60
61
62 note('Roundtripping');
63 {
64 my $importer_iso = Catmandu::Importer::MARC->new(file => 't/camel.mrc', type=> 'ISO');
65
66 ok $importer_iso , 'got an MARC/ISO importer';
67
68 my $records_iso = $importer_iso->to_array;
69
70 ok @$records_iso == 10, 'got all records';
71
72 my $marcline;
73
74 my $exporter = Catmandu::Exporter::MARC->new(file => \$marcline, type=> 'Line');
75
76 ok $exporter , 'got an MARC/Line exporter';
77
78 ok $exporter->add_many($records_iso) , 'add records';
79
80 ok $exporter->commit , 'commit';
81
82 my $importer_line = Catmandu::Importer::MARC->new(file => \$marcline, type=> 'Line');
83
84 ok $importer_line , 'got an MARC/Line importer';
85
86 my $records_line = $importer_line->to_array;
87
88 ok @$records_line == 10, 'got all records';
89
90 is_deeply $records_iso, $records_line, 'got expected result';
91 }
92
93 done_testing;