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 75 76 77 78 79 80 81 82 83 84
|
#!perl
use strict;
use warnings;
use Test::More;
use Test::Differences;
use Test::BDD::Cucumber::Parser;
use Test::BDD::Cucumber::Executor;
use Test::BDD::Cucumber::Harness::Data;
# Check that when we execute steps we get a nicely split string back for
# highlighting
for (
[
"Simple example",
"the quick brown fox",
qr/the (quick) brown (fox)/,
[
[ 0 => 'the ' ],
[ 1 => 'quick' ],
[ 0 => ' brown ' ],
[ 1 => 'fox' ],
]
],
[
"Non-capture",
"the quick brown fox",
qr/the (?:quick) brown (fox)/,
[
[ 0 => 'the quick brown ' ],
[ 1 => 'fox' ],
]
],
[
"Nested-capture",
"the quick brown fox",
qr/the (q(uic)k) brown (fox)/,
[
[ 0 => 'the ' ],
[ 1 => 'quick' ],
[ 0 => ' brown ' ],
[ 1 => 'fox' ],
]
],
[
"Multi-group",
"the quick brown fox",
qr/the (.)+ brown (fox)/,
[
[ 0 => 'the quic' ],
[ 1 => 'k' ],
[ 0 => ' brown ' ],
[ 1 => 'fox' ],
]
],
) {
my ( $test_name, $step_text, $step_re, $expected ) = @$_;
# Set up a feature
my $feature = Test::BDD::Cucumber::Parser->parse_string(
"Feature: Foo\n\tScenario:\n\t\tGiven $step_text\n"
);
# Set up step definitions
my $executor = Test::BDD::Cucumber::Executor->new();
$executor->add_steps(
[ Given => $step_re, sub { 1; } ],
);
# Instantiate the harness, and run it
my $harness = Test::BDD::Cucumber::Harness::Data->new();
$executor->execute( $feature, $harness );
# Get the step result
my $step = $harness->features->[0]->{'scenarios'}->[0]->{'steps'}->[0];
my $highlights = $step->{'highlights'};
is_deeply( $highlights, $expected, $test_name ) || eq_or_diff(
$highlights, $expected
);
}
done_testing();
|