Debian Codegraph @

t/Catmandu/Fix/Condition/marc_all_match.t

raw
1 #!perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Test::Exception;
7
8 my $pkg;
9
10 BEGIN {
11 $pkg = 'Catmandu::Fix::Condition::marc_all_match';
12 use_ok $pkg;
13 }
14
15 require_ok $pkg;
16
17 my $mrc = <<'MRC';
18 <?xml version="1.0" encoding="UTF-8"?>
19 <marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim">
20 <marc:record>
21 <marc:controlfield tag="001"> 92005291 </marc:controlfield>
22 <marc:datafield ind1="1" ind2="0" tag="245">
23 <marc:subfield code="a">Title / </marc:subfield>
24 <marc:subfield code="c">Name</marc:subfield>
25 </marc:datafield>
26 <marc:datafield ind1=" " ind2=" " tag="999">
27 <marc:subfield code="a">X</marc:subfield>
28 <marc:subfield code="a">Y</marc:subfield>
29 </marc:datafield>
30 <marc:datafield ind1=" " ind2=" " tag="999">
31 <marc:subfield code="a">Z</marc:subfield>
32 </marc:datafield>
33 </marc:record>
34 </marc:collection>
35 MRC
36
37 note 'marc_all_match(999,X)';
38 {
39 my $importer = Catmandu->importer(
40 'MARC',
41 file => \$mrc,
42 type => 'XML',
43 fix => 'if marc_all_match(999,X) add_field(test,failed) end'
44 );
45 my $record = $importer->first;
46
47 ok ! $record->{test} , 'ok matched nothing'
48 }
49
50 note 'marc_all_match(999,[XYZ])';
51 {
52 my $importer = Catmandu->importer(
53 'MARC',
54 file => \$mrc,
55 type => 'XML',
56 fix => 'if marc_all_match(999,[XYZ]) add_field(test,ok) end'
57 );
58 my $record = $importer->first;
59
60 is $record->{test} , 'ok' , 'ok matched everything'
61 }
62
63 done_testing;