Add a method that returns the regexp used to validate generated GUIDs. This should

prevent the regexp from proliferating all through tests and code.
Also, add a test for the method, which just checks that it returns a regexp.
This commit is contained in:
Colin Kuskie 2008-01-08 20:43:39 +00:00
parent f56c0873d8
commit fca9e9c633
2 changed files with 19 additions and 2 deletions

View file

@ -20,6 +20,7 @@ use Digest::MD5;
use Time::HiRes qw( gettimeofday usleep );
use MIME::Base64;
my $idValidator = qr/^[A-Za-z0-9_-]{22}$/;
=head1 NAME
@ -55,6 +56,19 @@ sub DESTROY {
}
#-------------------------------------------------------------------
=head2 getValidator
Get the regular expression used to validate generated GUIDs. This is just to prevent
regular expressions from being duplicated all over the place.
=cut
sub getValidator {
return $idValidator;
}
#-------------------------------------------------------------------
=head2 generate
@ -137,7 +151,7 @@ Returns true if $idString is a valid WebGUI guid.
sub valid {
my ($self, $idString) = @_;
return $idString =~ m/^[A-Za-z0-9_-]{22}$/;
return $idString =~ m/$idValidator/;
}

View file

@ -53,7 +53,7 @@ my @testSets = (
my $session = WebGUI::Test->session;
plan tests => scalar(@testSets) + 4;
plan tests => scalar(@testSets) + 5;
# generate
my $generateId = $session->id->generate();
@ -79,3 +79,6 @@ foreach my $testSet (@testSets) {
#
is($session->id->toHex('wjabZsKOb7kBBSiO3bQwzA'), 'c2369b66c28e6fb90105288eddb430cc', 'toHex works');
my $re = $session->id->getValidator;
is( ref $re, 'Regexp', 'getValidator returns a regexp object');