MARC-File-MARCMaker

 view release on metacpan or  search on metacpan

t/marcmaker.t  view on Meta::CPAN


=head1 NAME

marcmaker.t -- Tests for MARC::File::MARCMaker.

=head1 TO DO

Compare decoded and encoded versions of records in camel.mrk and camel.usmarc with each other.

Determine how to link as_marcmaker method from MARC::File::MARCMaker to MARC::Field without "only once" warning.

More comprehensive tests of character encoding/decoding.

=cut

use strict;
use warnings;

use Test::More tests=>10;

BEGIN { use_ok( 'MARC::Batch' ); }
BEGIN { use_ok( 'MARC::File::USMARC' ); }
BEGIN { use_ok( 'MARC::File::MARCMaker' ); }

if (UNIVERSAL::can('MARC::Field', 'as_marcmaker')) {
    warn "MARC::Field now has an as_marcmaker() method";
} 
else {
    no warnings;
    *MARC::Field::as_marcmaker = *MARC::File::MARCMaker::as_marcmaker;
}

###################################################
###################################################

#create MARC::Record object for manipulation
my $record = MARC::Record->new();

isa_ok( $record, 'MARC::Record', 'MARC record' );

$record->leader("00000nam  2200253 a 4500"); 
my $nfields = $record->add_fields(
    #control number so one is present
    ['001', "ttt05000001"
    ],
    #basic 008
    ['008', "050801s2005    ilu           000 0 eng d"
    ],
    #basic 245
    [245, "0","0",
        a => "Test record from text /",
        c => "Bryan Baldus ... [et al.].",
    ],
    [500, '', '',
        a => 'This is a test of ordinary features like replacement of the mnemonics for currency and dollar signs ($) and backslashes (backsolidus \ ) used for blanks in certain areas.'
    ],
    [500, '', '',
        a => 'This is a test for the conversion of curly braces; the opening curly brace ( { ) and the closing curly brace ( } ).'
    ],
    [500, '', '',
        a => "This is a test of diacritics like the uppercase Polish L in ¡âodâz, the uppercase Scandinavia O in ¢st, the uppercase D with crossbar in £uro, the uppercase Icelandic thorn in ¤ann, the uppercase digraph AE in ¥gir, the uppercase digrap...
    ],
    [650, '', '0',
        a => 'MARC records.',
    ],

    );
is( $nfields, 7, "All the fields added OK" );

my @fields500 = $record->field('500');

is($fields500[0]->as_marcmaker(), "=500  \\\\\$aThis is a test of ordinary features like replacement of the mnemonics for currency and dollar signs ({dollar}) and backslashes (backsolidus {bsol} ) used for blanks in certain areas.\n", join "\t", "Dol...

is($fields500[1]->as_marcmaker(), "=500  \\\\\$aThis is a test for the conversion of curly braces; the opening curly brace ( {lcub} ) and the closing curly brace ( {rcub} ).\n", join "\t", "Curly braces test ok", $fields500[1]->as_marcmaker());

my $rec_as_maker = MARC::File::MARCMaker::encode($record);

my $record_from_maker = MARC::File::MARCMaker::decode($rec_as_maker);

isa_ok( $record_from_maker, 'MARC::Record', 'MARC record from MARCMaker data' );

my @recoded_500s = $record_from_maker->field('500');
print $recoded_500s[0]->as_string(), "\n";

print $recoded_500s[1]->as_string(), "\n";

#######################
### Diacritics test ###
#######################

is ($fields500[2]->as_marcmaker(), "=500  \\\\\$aThis is a test of diacritics like the uppercase Polish L in {Lstrok}{acute}od{acute}z, the uppercase Scandinavia O in {Ostrok}st, the uppercase D with crossbar in {Dstrok}uro, the uppercase Icelandic t...

is ($recoded_500s[2]->as_string(), "This is a test of diacritics like the uppercase Polish L in ¡âodâz, the uppercase Scandinavia O in ¢st, the uppercase D with crossbar in £uro, the uppercase Icelandic thorn in ¤ann, the uppercase digraph AE in ¥gir...

#=500  \\$aThis is a test of diacritics like the uppercase Polish L in {Lstrok}{acute}od{acute}z, the uppercase Scandinavia O in {Ostrok}st, the uppercase D with crossbar in {Dstrok}uro, the uppercase Icelandic thorn in {THORN}ann, the uppercase digr...



( run in 1.001 second using v1.01-cache-2.11-cpan-71847e10f99 )