Debian Codegraph @

t/Catmandu/Fix/marc_paste.t

raw
1 #!perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Test::Exception;
7 use Catmandu;
8
9 my $pkg;
10
11 BEGIN {
12 $pkg = 'Catmandu::Fix::marc_paste';
13 use_ok $pkg;
14 }
15
16 require_ok $pkg;
17
18 my $mrc = <<'MRC';
19 <?xml version="1.0" encoding="UTF-8"?>
20 <marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim">
21 <marc:record>
22 <marc:controlfield tag="001"> 92005291 </marc:controlfield>
23 <marc:datafield ind1="1" ind2="0" tag="245">
24 <marc:subfield code="a">Title / </marc:subfield>
25 <marc:subfield code="c">Name</marc:subfield>
26 </marc:datafield>
27 <marc:datafield ind1=" " ind2=" " tag="998">
28 <marc:subfield code="a">X</marc:subfield>
29 <marc:subfield code="a">Y</marc:subfield>
30 </marc:datafield>
31 <marc:datafield ind1=" " ind2=" " tag="999">
32 <marc:subfield code="a">Z</marc:subfield>
33 </marc:datafield>
34 </marc:record>
35 </marc:collection>
36 MRC
37
38
39 note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl)';
40 {
41 my $importer = Catmandu->importer(
42 'MARC',
43 file => \$mrc,
44 type => 'XML',
45 fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl)'
46 );
47 my $record = $importer->first;
48
49 is_deeply $record->{record}->[-1],
50 [ '002' , ' ' , ' ' , '_' , ' 92005291 ' ]
51 , 'marc_copy(001,cntrl)';
52 }
53
54
55 note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245)';
56 {
57 my $importer = Catmandu->importer(
58 'MARC',
59 file => \$mrc,
60 type => 'XML',
61 fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245)'
62 );
63 my $record = $importer->first;
64
65 is_deeply $record->{record}->[-3],
66 [ '002' , ' ' , ' ' , '_' , ' 92005291 ' ]
67 , 'marc_copy(001,cntrl)';
68 }
69
70 note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245c)';
71 {
72 my $importer = Catmandu->importer(
73 'MARC',
74 file => \$mrc,
75 type => 'XML',
76 fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245c)'
77 );
78 my $record = $importer->first;
79
80 is_deeply $record->{record}->[-3],
81 [ '002' , ' ' , ' ' , '_' , ' 92005291 ' ]
82 , 'marc_copy(001,cntrl)';
83 }
84
85 note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245x)';
86 {
87 my $importer = Catmandu->importer(
88 'MARC',
89 file => \$mrc,
90 type => 'XML',
91 fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245x)'
92 );
93 my $record = $importer->first;
94
95 is_deeply $record->{record}->[-3],
96 [ '245' , '1' , '0' , 'a' , 'Title / ', 'c' , 'Name' ]
97 , 'marc_copy(001,cntrl)';
98 }
99
100 note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245c,equals:Name)';
101 {
102 my $importer = Catmandu->importer(
103 'MARC',
104 file => \$mrc,
105 type => 'XML',
106 fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245c,equals:Name)'
107 );
108 my $record = $importer->first;
109
110 is_deeply $record->{record}->[-3],
111 [ '002' , ' ' , ' ' , '_' , ' 92005291 ' ]
112 , 'marc_copy(001,cntrl)';
113 }
114
115 note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245,equals:"Title / Name")';
116 {
117 my $importer = Catmandu->importer(
118 'MARC',
119 file => \$mrc,
120 type => 'XML',
121 fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245,equals:"Title / Name")'
122 );
123 my $record = $importer->first;
124
125 is_deeply $record->{record}->[-3],
126 [ '002' , ' ' , ' ' , '_' , ' 92005291 ' ]
127 , 'marc_copy(001,cntrl)';
128 }
129
130 done_testing;