Skip to content

Commit e1d8cd8

Browse files
authored
[Perl] Prefer the longest step keyword (cucumber#408)
1 parent 42bcdf5 commit e1d8cd8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
1515
- [PHP] Prefer the longest step keyword ([#403](https://github.com/cucumber/gherkin/pull/403))
1616
- [Go] Prefer the longest step keyword ([#403](https://github.com/cucumber/gherkin/pull/404))
1717
- [JavaScript] Prefer the longest step keyword ([#407](https://github.com/cucumber/gherkin/pull/407))
18+
- [Perl] Prefer the longest step keyword ([#408](https://github.com/cucumber/gherkin/pull/408))
1819
- [Ruby] Prefer the longest step keyword ([#409](https://github.com/cucumber/gherkin/pull/409))
1920
- [Python] Prefer the longest step keyword ([#410](https://github.com/cucumber/gherkin/pull/410))
2021

perl/lib/Gherkin/TokenMatcher.pm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use List::Util qw(any first reduce);
88
our $LANGUAGE_RE = qr/^\s*#\s*language\s*:\s*([a-zA-Z\-_]+)\s*$/o;
99

1010
use Class::XSAccessor accessors => [
11-
qw/dialect _default_dialect_name _indent_to_remove _active_doc_string_separator _keyword_types /,
11+
qw/dialect _default_dialect_name _indent_to_remove _active_doc_string_separator _keyword_types _sorted_step_keywords /,
1212
];
1313

1414
use Cucumber::Messages;
@@ -51,6 +51,13 @@ sub change_dialect {
5151
[ @{ $self->dialect->And }, @{ $self->dialect->But } ],
5252
Cucumber::Messages::Step::KEYWORDTYPE_CONJUNCTION);
5353
$self->_keyword_types( $keyword_types );
54+
$self->_sorted_step_keywords(
55+
[ sort {
56+
length $b <=> length $a # longest keyword first (See #400)
57+
} map {
58+
@{ $self->dialect->$_ }
59+
} qw/Given When Then And But/ ]
60+
);
5461
}
5562

5663
sub reset {
@@ -213,7 +220,7 @@ sub _unescaped_docstring {
213220

214221
sub match_StepLine {
215222
my ( $self, $token ) = @_;
216-
my @keywords = map { @{ $self->dialect->$_ } } qw/Given When Then And But/;
223+
my @keywords = @{ $self->_sorted_step_keywords };
217224
my $line = $token->line;
218225

219226
for my $keyword (@keywords) {

0 commit comments

Comments
 (0)