X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=blobdiff_plain;f=Equinox-Migration%2Ft%2F02-SubfieldMapper.t;h=c948fdd5afcc2d33a184712049b2b8cc473b8c72;hp=680f348da7b0e53ca4dad0ffc984d5f5cee681c9;hb=2e53c25a974483f4d2519682d38455401cbde08e;hpb=787d7acc9b22dbb935074dd3d5c2da470819686b diff --git a/Equinox-Migration/t/02-SubfieldMapper.t b/Equinox-Migration/t/02-SubfieldMapper.t index 680f348..c948fdd 100644 --- a/Equinox-Migration/t/02-SubfieldMapper.t +++ b/Equinox-Migration/t/02-SubfieldMapper.t @@ -1,10 +1,13 @@ #!perl -T -#use Test::More tests => 33; -use Test::More qw(no_plan); +use Test::More tests => 41; +#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'); @@ -36,10 +46,6 @@ $tokens = { field => 'foo', tag => 650, sub => 'qq' }; eval { $sm->validate($tokens) }; is ($@, "Invalid subfield code (line 1)\n", 'over-length subfield'); -$tokens = { field => 'foo', tag => 650, sub => 'a', mod => 'bar' }; -eval { $sm->validate($tokens) }; -is ($@, "Unknown chunk (line 1)\n", 'Extra, non-comment content'); - # and some which should have no problems $tokens = { field => 'foo', tag => 650, sub => 'a' }; eval { $sm->validate($tokens) }; @@ -56,7 +62,7 @@ is ($@, "Fieldnames must be unique (line 1)\n", 'dupe fieldname'); $sm->{tags}{650}{a} = 1; $tokens = { field => 'bar', tag => 650, sub => 'a', mod => '#', 'this', 'is', 'a', 'comment' }; eval { $sm->validate($tokens) }; -is ($@, "Subfields cannot be multimapped (line 1)\n", 'dupe fieldname'); +is ($@, "Subfields cannot be mapped twice (line 1)\n", 'dupe fieldname'); # test load from file $sm = Equinox::Migration::SubfieldMapper->new( file => "./t/corpus/sm0.txt" ); @@ -64,14 +70,31 @@ 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->{fields}{type}{mod}, 0); -is ($sm->{fields}{note}{mod}, 'multi'); +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}{note}{mods}{multi}, 1); +is ($sm->mods('zzz'), undef, 'nonexistant field'); +is_deeply ($sm->mods('note'), { multi => 1}, 'multi'); +is_deeply ($sm->mods('note_alt'), { multi => 1, req => 1 }, 'multi, req'); +is_deeply ($sm->mods('date_a'), { foo => 1, bar => 1, quux => 1 }); +is_deeply ($sm->filters('date_a'), ['one two three']); +is_deeply ($sm->filters('type'), ['foo']); +