X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=blobdiff_plain;f=Equinox-Migration%2Ft%2F01-SimpleTagList.t;h=0d4c9a4f32914b273caa0ac01e7d6380a84e3e11;hp=0e8c2d985c2d449e1652333fd2bdc9fe451eda72;hb=7b6f5557a05fa7e4cd09f433398ea4f6368ae519;hpb=2c1a0eff7bc0ae19b91f43fce329298fbe1826f5 diff --git a/Equinox-Migration/t/01-SimpleTagList.t b/Equinox-Migration/t/01-SimpleTagList.t index 0e8c2d9..0d4c9a4 100644 --- a/Equinox-Migration/t/01-SimpleTagList.t +++ b/Equinox-Migration/t/01-SimpleTagList.t @@ -1,9 +1,14 @@ #!perl -T -use Test::More tests => 25; +use Test::More tests => 51; +#use Test::More qw(no_plan); + use Equinox::Migration::SimpleTagList; # baseline object creation +eval { my $stl = Equinox::Migration::SimpleTagList->new( file => "thefileisalie.txt" ) }; +is ($@ =~ /^Can't open tags file 'thefileisalie\.txt':/, 1, 'cannot open that'); + my $stl = Equinox::Migration::SimpleTagList->new(); is(ref $stl, "Equinox::Migration::SimpleTagList", "self is self"); @@ -16,6 +21,17 @@ is ($stl->has(904), 1, 'can has tag'); $stl->remove_tag(904); is ($stl->has(904), 0, 'can not has tag'); +eval { $stl->add_tag('q') }; +is ($@, "Values must be numeric\n"); +eval { $stl->add_tag(-37) }; +is ($@, "Values must be valid tags (0-999)\n"); +eval { $stl->add_tag(1027) }; +is ($@, "Values must be valid tags (0-999)\n"); +eval { $stl->add_tag(89) }; +is ($@, "Tag '89' specified twice\n"); +eval { $stl->remove_tag(11) }; +is ($@, "Tag '11' isn't in the list\n"); + # range addition, as_hashref, as_listref $stl->add_range("198..201"); is_deeply ($stl->as_hashref, { 89 => 1, 198 => 1, 199 => 1, 200 => 1, 201 => 1 }); @@ -23,6 +39,18 @@ is_deeply ($stl->as_listref, [ 89, 198, 199, 200, 201 ]); $stl->add_range("008..011"); is_deeply ($stl->as_listref, [ 8, 9, 10, 11, 89, 198, 199, 200, 201 ]); +$stl->{conf}{except} = 1; +eval { $stl->add_range("300..311") }; +is ($@, "Exception ranges must be within last addition range (300..311)\n"); +eval { $stl->add_range("10..311") }; +is ($@, "Exception ranges must be within last addition range (10..311)\n"); +eval { $stl->add_range("6..11") }; +is ($@, "Exception ranges must be within last addition range (6..11)\n"); +eval { $stl->add_range("17..16") }; +is ($@, "Ranges must be 'low..high' (17 is greater than 16)\n"); + + + # creation with file $stl = Equinox::Migration::SimpleTagList->new( file => "./t/corpus/stl-0.txt"); is ($stl->has(11), 1); @@ -31,14 +59,42 @@ is ($stl->has(12), 1); is ($stl->has('012'), 1); is ($stl->has(241), 1); is ($stl->has(359), 1); +is ($stl->has(400), 1); +is ($stl->has(416), 1); is ($stl->has(652), 1); is ($stl->has(654), 1); is ($stl->has(656), 1); is ($stl->has(658), 1); +is ($stl->has(797), 1, 'exception is inline commented out'); is ($stl->has(872), 1); is ($stl->has(900), 1); is ($stl->has(999), 1); is ($stl->has(988), 1); +is ($stl->has(411), 0, 'exception'); +is ($stl->has(500), 0, 'inclusion commented out'); is ($stl->has(655), 0, 'exception'); +is ($stl->has(915), 0, 'exception'); is ($stl->has(987), 0, 'exception'); -is ($stl->has(400), 0, 'not in input set'); +is ($stl->has(500), 0, 'not in input set'); + +$stl = Equinox::Migration::SimpleTagList->new( file => "./t/corpus/stl-1.txt"); +is ($stl->has(258), 1); +is ($stl->has(259), 0, 'exception'); +is ($stl->has(274), 1); +is ($stl->has(275), 0, 'exception'); +is ($stl->has(286), 1); +is ($stl->has(285), 0, 'exception'); +is ($stl->has(305), 1); +is ($stl->has(304), 0, 'exception'); + +# file with bad token +$. = 0; +$stl = Equinox::Migration::SimpleTagList->new; +eval {$stl->generate("./t/corpus/stl-2.txt")}; +is ($@, "Unknown chunk fnord in tags file (line 1)\n"); + +# file with except in wrong place +$. = 0; +$stl = Equinox::Migration::SimpleTagList->new; +eval {$stl->generate("./t/corpus/stl-3.txt")}; +is ($@, "Keyword 'except' can only follow a range (line 1)\n");