Debian Codegraph @

t/Catmandu/Importer/MARC/Line.t

raw
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::Line';
14 use_ok $pkg;
15 }
16
17 require_ok $pkg;
18
19 my $record =<<'EOF';
20 00251nas a2200121 c 4500
21 001 987874829
22 007 cr||||||||||||
23 022 $a 1940-5758
24 041 $a eng
25 245 00 $a Code4Lib journal $b C4LJ
26 246 3 $a C4LJ
27 362 0 $a 1.2007 -
28 856 4 $u http://journal.code4lib.org/
29 999 $= foo $< bar $$ baz
30
31 EOF
32
33 my $expected = {
34 '_id' => '987874829',
35 'record' => [
36 ['LDR', ' ', ' ', '_', '00251nas a2200121 c 4500'],
37 ['001', ' ', ' ', '_', '987874829'],
38 ['007', ' ', ' ', '_', 'cr||||||||||||'],
39 ['022', ' ', ' ', 'a', '1940-5758'],
40 ['041', ' ', ' ', 'a', 'eng'],
41 [245, '0', '0', 'a', 'Code4Lib journal', 'b', 'C4LJ'],
42 [246, '3', ' ', 'a', 'C4LJ'],
43 [362, '0', ' ', 'a', '1.2007 -'],
44 [856, '4', ' ', 'u', 'http://journal.code4lib.org/'],
45 [999, ' ', ' ', '=', 'foo', '<', 'bar', '$', 'baz']
46 ]
47 };
48
49 note('Importing from MARC/Line inline');
50 {
51 my $importer = Catmandu::Importer::MARC->new( file => \$record, type => 'Line' );
52
53 ok $importer , 'got an MARC/Line importer';
54
55 my $result = $importer->first;
56
57 ok $result , 'got a record';
58
59 is_deeply $result , $expected , 'got expected result';
60 }
61
62 note('Importing from MARC/Line file');
63 {
64 my $importer = Catmandu::Importer::MARC->new( file => 't/code4lib.line', type => "Line" );
65
66 ok $importer , 'got an MARC/Line importer';
67
68 my $result = $importer->first;
69
70 is_deeply $result, $expected , 'got expected result';
71 }
72
73 done_testing;