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");
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');
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');