Debian Codegraph @

t/Catmandu/Fix/Condition/marc_has.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 Catmandu::Fix;
9 use utf8;
10
11 my $pkg;
12
13 BEGIN {
14 $pkg = 'Catmandu::Fix::Condition::marc_has';
15 use_ok $pkg;
16 }
17
18 require_ok $pkg;
19
20 my $fixes = <<EOF;
21 if marc_has(245)
22 add_field(test.\$append,'has 245')
23 end
24
25 if marc_has_many(245)
26 add_field(test.\$append,'has many 245')
27 end
28
29 if marc_has_many(CAT)
30 add_field(test.\$append,'has many CAT')
31 end
32
33 if marc_has_many(920a)
34 add_field(test.\$append,'has many 920a')
35 end
36
37 unless marc_has_many(100a)
38 add_field(test.\$append,'has not more than one 100a')
39 end
40 EOF
41
42 my $record =<<'EOF';
43 000000002 FMT L BK
44 000000002 LDR L 00000nam^a2200301^i^4500
45 000000002 001 L 000000002
46 000000002 1001 L $$aMusterman
47 000000002 24510 L $$aCatmandu Test
48 000000002 650 0 L $$aPerl
49 000000002 650 0 L $$aMARC$$aMARC2
50 000000002 650 0 L $$a加德滿都
51 000000002 920 0 L $$ablue$$ared
52 000000002 CAT 0 L $$atest
53 000000002 CAT 0 L $$atest
54 EOF
55
56 my $fixer = Catmandu::Fix->new(fixes => [$fixes]);
57 my $importer = Catmandu::Importer::MARC->new( file => \$record, type => "ALEPHSEQ" );
58 my $records = $fixer->fix($importer)->to_array;
59
60 my $errors = $records->[0]->{test};
61
62 is_deeply $errors , [
63 'has 245' ,
64 'has many CAT' ,
65 'has many 920a' ,
66 'has not more than one 100a' ,
67 ] , 'got the expected results';
68
69 done_testing;