Debian Codegraph @

t/Catmandu/Fix/marc_replace_all.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
10 my $pkg;
11
12 BEGIN {
13 $pkg = 'Catmandu::Fix::marc_replace_all';
14 use_ok $pkg;
15 }
16
17 require_ok $pkg;
18
19 #---
20 {
21 my $fixer = Catmandu::Fix->new(fixes => [q|marc_replace_all('100a','Tobias','John')|,q|marc_map('100a','test')|]);
22 my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
23 my $record = $fixer->fix($importer->first);
24
25 like $record->{test}, qr/^Martinsson, John,$/, q|fix: marc_replace_all('100a','Tobias','John')|;
26 }
27
28 #---
29 {
30 my $fixer = Catmandu::Fix->new(fixes => [q|marc_replace_all('630','Active','Silly')|,q|marc_map('630a','test.$append')|]);
31 my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
32 my $record = $fixer->fix($importer->first);
33
34 is_deeply $record->{test}, [
35 'Silly server pages.' ,
36 'SillyX.'
37 ], q|fix: marc_replace_all('630a','Active','Silly')|;
38 }
39
40
41 #---
42 {
43 my $fixer = Catmandu::Fix->new(fixes => [q|marc_replace_all('630','(Active)','{$1}')|,q|marc_map('630a','test.$append')|]);
44 my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
45 my $record = $fixer->fix($importer->first);
46
47 is_deeply $record->{test}, [
48 '{Active} server pages.' ,
49 '{Active}X.'
50 ], q|fix: marc_replace_all('630a','Active','{Active}')|;
51 }
52
53 done_testing;