| 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 Catmandu::Fix::Inline::marc_map qw(:all); |
| 10 |
use utf8; |
| 11 |
|
| 12 |
my $pkg; |
| 13 |
|
| 14 |
BEGIN { |
| 15 |
$pkg = 'Catmandu::Fix::marc_remove'; |
| 16 |
use_ok $pkg; |
| 17 |
} |
| 18 |
|
| 19 |
require_ok $pkg; |
| 20 |
|
| 21 |
my $fixer = Catmandu::Fix->new(fixes => [ |
| 22 |
q|marc_remove('245')|, |
| 23 |
q|marc_remove('100a')|, |
| 24 |
q|marc_remove('082[1,1]a')|, |
| 25 |
q|marc_remove('050[,0]ab')|, |
| 26 |
]); |
| 27 |
my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" ); |
| 28 |
my $record = $importer->first; |
| 29 |
|
| 30 |
my $title = marc_map($record,'245'); |
| 31 |
my $author = marc_map($record,'100'); |
| 32 |
my $dewey = marc_map($record,'082'); |
| 33 |
my $lccn = marc_map($record,'050'); |
| 34 |
|
| 35 |
ok $title, 'got a title'; |
| 36 |
like $author , qr/^Martinsson, Tobias,1976-$/ , 'got an author'; |
| 37 |
ok $dewey, 'got a dewey'; |
| 38 |
ok $lccn , 'got a lccn'; |
| 39 |
|
| 40 |
my $fixed_record = $fixer->fix($record); |
| 41 |
|
| 42 |
my $title2 = marc_map($fixed_record,'245'); |
| 43 |
my $author2 = marc_map($fixed_record,'100'); |
| 44 |
my $dewey2 = marc_map($fixed_record,'082'); |
| 45 |
my $lccn2 = marc_map($fixed_record,'050'); |
| 46 |
|
| 47 |
ok (!defined $title2, 'deleted the title'); |
| 48 |
|
| 49 |
like $author2 , qr/^1976-$/ , 'removed 100-a'; |
| 50 |
|
| 51 |
ok (defined $dewey2, 'didnt delete dewey'); |
| 52 |
|
| 53 |
ok (!defined $lccn2, 'deleted lccn'); |
| 54 |
|
| 55 |
done_testing; |