1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
use 5.010;
use warnings;
use Test::More;
plan 'no_plan';
my %hash = (
dore => 'a portal',
me => 'a name I call myself',
fa => 'a long long way to run',
);
my $listified = do {
use Regexp::Grammars;
qr{ <[WORD=%hash{ .{2} }]>+ }xms;
};
my $first_only = do {
use Regexp::Grammars;
qr{ <WORD=%hash {.{2}} > }xms;
};
my $first_only_override = do {
use Regexp::Grammars;
qr{ <WORD=%hash {.{2}} > <token: hk> \w+ }xms;
};
my $first_two_override = do {
use Regexp::Grammars;
qr{ <WORD1=%hash {.{2}} > <WORD2=%hash{..}> <token: hk> \w+ }xms;
};
my $no_cap = do {
use Regexp::Grammars;
qr{ <%hash{..}>+ }xms;
};
while (my $line = <DATA>) {
my ($input, $expected) = split /\s+/, $line;
my $expected_data = eval $expected;
if ($input =~ $listified) {
is_deeply $/{WORD}, $expected_data, "list: $input";
}
else { is 'FAIL', $expected, "list: $input"; }
if ($input =~ $first_only) {
is $/{WORD}, $expected_data->[0], "scalar: $input";
}
else { is 'FAIL', $expected, "scalar: $input"; }
if ($input =~ $first_only_override) {
is $/{WORD}, $expected_data->[0], "scalar (override): $input";
}
else { is 'FAIL', $expected, "scalar (override): $input"; }
if (@{$expected_data} > 1) {
if ($input =~ $first_two_override) {
is $/{WORD1}, $expected_data->[0], "scalars[0] (override): $input";
is $/{WORD2}, $expected_data->[1], "scalars[1] (override): $input";
}
else { is 'FAIL', $expected, "scalars (override): $input"; }
}
if ($input =~ $no_cap) { isnt 'FAIL', $expected, "no-cap: $input"; }
else { is 'FAIL', $expected, "no-cap: $input"; }
}
__DATA__
dorefameredo ['fa','me']
dorefamell ['fa','me']
zzzzz FAIL
zzzdoremezzz ['me']
|