use strict;
use warnings;
use Test::More tests => 1;
my $sample_string = '240 x 240 x 2/3600';
my $number = qr/1?\d{1,4}/;
my $valid = $sample_string =~ m{$number x $number x $number/$number};
ok($valid, 'Sample string');
####
use strict;
use warnings;
use Test::More tests => 6;
my @valid_strings = (
['240 x 240 x 2/3600', 'Sample'],
['10000 x 240 x 2/3600', 'Max number'],
['1 x 240 x 2/3600', 'Min number'],
);
#my $number = qr/1?\d{1,4}/;
my $number = qr/10000|[1-9]\d{0,3}/;
my $valid = qr {\A$number x $number x $number/$number\z};
foreach my $case (@valid_strings) {
like $case->[0], $valid, $case->[1]
}
my @invalid_strings = (
['240 * 240 x 2/3600', 'Missing operator'],
['10001 x 240 x 2/3600', 'number exceeds max'],
['0 x 240 x 2/3600', 'number less than minimum'],
);
foreach my $case (@invalid_strings) {
unlike $case->[0], $valid, $case->[1]
}
####
1..6
ok 1 - Sample
ok 2 - Max number
ok 3 - Min number
ok 4 - Missing operator
ok 5 - number exceeds max
ok 6 - number less than minimum