From 70d10b65e4a572bc65044c1d798c1bd4164e1ddf Mon Sep 17 00:00:00 2001 From: Shawn Boyette Date: Tue, 24 Mar 2009 18:55:57 +0000 Subject: [PATCH] coverage testing updates --- Equinox-Migration/t/02-SubfieldMapper.t | 29 ++++++++++++++++++++++++++--- 1 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Equinox-Migration/t/02-SubfieldMapper.t b/Equinox-Migration/t/02-SubfieldMapper.t index 680f348..568c3c0 100644 --- a/Equinox-Migration/t/02-SubfieldMapper.t +++ b/Equinox-Migration/t/02-SubfieldMapper.t @@ -5,6 +5,9 @@ use Test::More qw(no_plan); use Equinox::Migration::SubfieldMapper; # baseline object creation +eval { my $sm = Equinox::Migration::SubfieldMapper->new( file => "thefileisalie.txt" ) }; +is ($@ =~ /^Can't open file:/, 1, 'cannot open that'); + my $sm = Equinox::Migration::SubfieldMapper->new(); is(ref $sm, "Equinox::Migration::SubfieldMapper", "self is self"); @@ -19,6 +22,13 @@ $tokens = { field => 'foo', tag => 99 }; eval { $sm->validate($tokens) }; is ($@, "Required field missing (line 1)\n", 'only 2 fields'); +$tokens = { field => '9wm', tag => 650, sub => 'a' }; +eval { $sm->validate($tokens) }; +is ($@, "Fieldnames must start with letter (line 1)\n", 'field must start with letter'); + +$tokens = { field => 'foo', tag => 'q', sub => 'a' }; +eval { $sm->validate($tokens) }; +is ($@, "Invalid tag (line 1)\n", 'nonnumeric tag'); $tokens = { field => 'foo', tag => -1, sub => 'a' }; eval { $sm->validate($tokens) }; is ($@, "Invalid tag (line 1)\n", 'tag value < 0'); @@ -64,14 +74,27 @@ is(ref $sm, "Equinox::Migration::SubfieldMapper", "self is self"); is ($sm->{tags}{949}{a}, 'call_number'); is ($sm->{tags}{999}{a}, 'call_number_alt'); +# has method tests +is ($sm->has, undef, 'has nothing'); is ($sm->has(949), 1, 'has tag'); +is ($sm->has(959), 0, 'has not tag'); is ($sm->has(999, 'a'), 1, 'has tag and subfield'); is ($sm->has('call_number'), 1, 'has fieldname'); -is ($sm->has('call_number', 949), 1, 'has fieldname'); -is ($sm->has('call_number', 949, 'a'), 1, 'has fieldname'); - +is ($sm->has('call_number', 949), 1, 'has tag'); +is ($sm->has('call_number', 700), 0, 'does not has tag'); +is ($sm->has('call_number', 949, 'a'), 1, 'has code'); +is ($sm->has('call_number', 949, 'q'), 0, 'does not has code'); +# field method tests is ($sm->{fields}{call_number}{tag}, 949); is ($sm->{fields}{call_number}{sub}, 'a'); +is ($sm->field, undef, 'null mapping is undef'); +is ($sm->field(650), undef, 'half-null mapping is undef'); +is ($sm->field(650,'z'), undef, 'tag+code not mapped'); +is ($sm->field(949,'a'), 'call_number', 'mapping returned'); + +# mod method tests is ($sm->{fields}{type}{mod}, 0); is ($sm->{fields}{note}{mod}, 'multi'); +is ($sm->mod('zzz'), undef, 'nonexistant field'); +is ($sm->mod('note'), 'multi', 'multi'); -- 1.7.2.5