| 1 |
#!perl |
| 2 |
|
| 3 |
|
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
|
| 7 |
use Test2::V0; |
| 8 |
use Test2::Tools::Exception qw(lives dies); |
| 9 |
use YAML qw(LoadFile); |
| 10 |
|
| 11 |
|
| 12 |
use Cucumber::TagExpressions; |
| 13 |
|
| 14 |
plan skip_all => 'AUTHOR_TESTING not enabled' |
| 15 |
if not $ENV{AUTHOR_TESTING}; |
| 16 |
|
| 17 |
my $cases = LoadFile('../testdata/evaluations.yml'); |
| 18 |
|
| 19 |
for my $case ( @{ $cases } ) { |
| 20 |
my $evaluator; |
| 21 |
ok( |
| 22 |
lives { |
| 23 |
$evaluator = Cucumber::TagExpressions->parse( $case->{expression} ); |
| 24 |
}, |
| 25 |
qq{Parsing "$case->{expression}"} ) |
| 26 |
or diag($@); |
| 27 |
|
| 28 |
ok( $evaluator, "Have an evaluator object from the parser" ); |
| 29 |
if ($evaluator) { |
| 30 |
for my $test ( @{ $case->{tests} } ) { |
| 31 |
my $result = $evaluator->evaluate( @{ $test->{variables} } ); |
| 32 |
is( $result ? "true" : "false", |
| 33 |
$test->{result}, |
| 34 |
"Evaluating $case->{expression} with variables @{$test->{variables}}" ); |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
$cases = LoadFile('../testdata/errors.yml'); |
| 41 |
|
| 42 |
for my $case ( @{ $cases } ) { |
| 43 |
like( |
| 44 |
dies { |
| 45 |
Cucumber::TagExpressions->parse( $case->{expression} ); |
| 46 |
}, |
| 47 |
qr/\Q$case->{error}\E/, |
| 48 |
qq{Parsing "$case->{expression}"} ); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
$cases = LoadFile('../testdata/parsing.yml'); |
| 53 |
|
| 54 |
for my $case ( @{ $cases } ) { |
| 55 |
my $evaluator; |
| 56 |
ok( |
| 57 |
lives { |
| 58 |
$evaluator = Cucumber::TagExpressions->parse( $case->{expression} ); |
| 59 |
}, |
| 60 |
qq{Parsing "$case->{expression}"} ) |
| 61 |
or diag($@); |
| 62 |
|
| 63 |
is( $evaluator->stringify, |
| 64 |
$case->{formatted}, |
| 65 |
"Stringified parser for $case->{expression}" ); |
| 66 |
} |
| 67 |
|
| 68 |
done_testing; |