From: Shawn Boyette Date: Wed, 18 Mar 2009 17:22:30 +0000 (+0000) Subject: more testing, more fixes; removal of single-except rule X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=commitdiff_plain;h=0a1fe57919524c3f47b28ccbac50fad8ac9cd8df more testing, more fixes; removal of single-except rule --- diff --git a/Equinox-Migration/lib/Equinox/Migration/SimpleTagList.pm b/Equinox-Migration/lib/Equinox/Migration/SimpleTagList.pm index 301094b..25ef631 100644 --- a/Equinox-Migration/lib/Equinox/Migration/SimpleTagList.pm +++ b/Equinox-Migration/lib/Equinox/Migration/SimpleTagList.pm @@ -112,7 +112,6 @@ sub generate { $self->{conf}{lastwasrange} = 0; $self->{conf}{range}{high} = 0; $self->{conf}{range}{low} = 0; - $self->{conf}{except} = 0; my @chunks = split /\s+/; while (my $chunk = shift @chunks) { @@ -120,12 +119,14 @@ sub generate { # single values if ($chunk =~ /^\d{1,3}$/) { $self->add_tag($chunk); + $self->{conf}{except} = 0; next; } # ranges if ($chunk =~ /^\d{1,3}\.\.\d{1,3}$/) { $self->add_range($chunk); + $self->{conf}{except} = 0; next; } @@ -133,8 +134,6 @@ sub generate { if ($chunk eq 'except') { die "Keyword 'except' can only follow a range (line $.)\n" unless $self->{conf}{lastwasrange}; - die "Keyword 'except' may only occur once per line (line $.)\n" - if $self->{conf}{except}; $self->{conf}{except} = 1; next; } @@ -158,7 +157,7 @@ sub add_range { if ($low > $high); if ($self->{conf}{except}) { die "Exception ranges must be within last addition range ($low..$high)\n" - if ($low < $self->{range}{low} or $high > $self->{range}{high}); + if ($low < $self->{conf}{range}{low} or $high > $self->{conf}{range}{high}); } for my $tag ($low..$high) { $self->add_tag($tag) @@ -183,13 +182,13 @@ sub add_tag { unless ($tag >= 0 and $tag <= 999); if ($self->{conf}{except}) { - $self->remove_tag($tag) + $self->remove_tag($tag); } else { die "Tag '$tag' specified twice\n" if $self->{tags}{$tag}; $self->{tags}{$tag} = 1; + $self->{conf}{lastwasrange} = 0; } - $self->{conf}{lastwasrange} = 0; } =head2 remove_tag @@ -209,14 +208,6 @@ sub remove_tag { Shawn Boyette, C<< >> -=head1 TODO - -=over - -=item * Remove single-except rule? - -=back - =head1 BUGS Please report any bugs or feature requests to the above email address. @@ -230,7 +221,7 @@ You can find documentation for this module with the perldoc command. =head1 COPYRIGHT & LICENSE -Copyright 2009 Shawn Boyette, all rights reserved. +Copyright 2009 Equinox, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/Equinox-Migration/t/01-SimpleTagList.t b/Equinox-Migration/t/01-SimpleTagList.t index 0e8c2d9..8a6bc7d 100644 --- a/Equinox-Migration/t/01-SimpleTagList.t +++ b/Equinox-Migration/t/01-SimpleTagList.t @@ -1,6 +1,6 @@ #!perl -T -use Test::More tests => 25; +use Test::More tests => 33; use Equinox::Migration::SimpleTagList; # baseline object creation @@ -42,3 +42,13 @@ is ($stl->has(988), 1); is ($stl->has(655), 0, 'exception'); is ($stl->has(987), 0, 'exception'); is ($stl->has(400), 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'); diff --git a/Equinox-Migration/t/corpus/stl-0.txt b/Equinox-Migration/t/corpus/stl-0.txt index 57ae957..b6c675f 100644 --- a/Equinox-Migration/t/corpus/stl-0.txt +++ b/Equinox-Migration/t/corpus/stl-0.txt @@ -5,4 +5,4 @@ 696..699 720 755 796..799 850 852 870..879 886 890 896..899 -900..999 except 935 987 994 +900..999 except 935 except 987 except 994 diff --git a/Equinox-Migration/t/corpus/stl-1.txt b/Equinox-Migration/t/corpus/stl-1.txt new file mode 100644 index 0000000..2844456 --- /dev/null +++ b/Equinox-Migration/t/corpus/stl-1.txt @@ -0,0 +1,3 @@ +250 254 256..261 except 259 270..290 except 275..285 +300..305 except except except except except 304 +