Skip to content

Commit 0721a27

Browse files
authored
.net: Handle all ambiguous keywords properly (#435)
By using the first duplicate keyword: ``` .ToDictionary(item => item.Key, item => item.First()); ``` GherkinDialect assumes that the AsteriskKeyword is the only duplicate keyword. Which probably isn't true. By using `Unknown` in case of ambiguity: ``` .ToDictionary(item => item.Key, items => items.Count() == 1 ? items.First() : StepKeywordType.Unknown); ``` that problems is avoided.
1 parent 08fb829 commit 0721a27

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
88

99
## [Unreleased]
1010
### Fixed
11+
- [.Net] Handle all ambiguous keywords properly ([#435](https://github.com/cucumber/gherkin/pull/435))
1112
- [Java] Optimize `GherkinLine.substringTrimmed` ([#444](https://github.com/cucumber/gherkin/pull/444))
1213
- [Java] Improve performance with a generated keyword matcher ([#445](https://github.com/cucumber/gherkin/pull/445))
1314

@@ -29,7 +30,6 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
2930
- [Go] Trim trailing tab characters from title and step lines ([#441](https://github.com/cucumber/gherkin/pull/441))
3031
- [Java] Use a more consistent definition of whitespace ([#442](https://github.com/cucumber/gherkin/pull/442))
3132

32-
3333
## [33.0.0] - 2025-07-07
3434
### Changed
3535
- [Elixir, Go, JavaScript, Java, Perl, Php, Ruby] Update dependency messages to v28 ([#420](https://github.com/cucumber/gherkin/pull/420))

dotnet/Gherkin/GherkinDialect.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ public class GherkinDialect(
3838
.OrderByDescending(x => x.Length) // To avoid conflicts when some keywords are prefixes of others, try the longest keywords first.
3939
.ToArray();
4040

41-
public IDictionary<string, StepKeywordType> StepKeywordTypes { get; } = new[] { new { Keyword = AsteriskKeyword, Type = StepKeywordType.Unknown } }
42-
.Concat(givenStepKeywords.Select(kw => new { Keyword = kw, Type = StepKeywordType.Context }))
41+
public IDictionary<string, StepKeywordType> StepKeywordTypes { get; } =
42+
givenStepKeywords.Select(kw => new { Keyword = kw, Type = StepKeywordType.Context })
4343
.Concat(whenStepKeywords.Select(kw => new { Keyword = kw, Type = StepKeywordType.Action }))
4444
.Concat(thenStepKeywords.Select(kw => new { Keyword = kw, Type = StepKeywordType.Outcome }))
4545
.Concat(andStepKeywords.Select(kw => new { Keyword = kw, Type = StepKeywordType.Conjunction }))
4646
.Concat(butStepKeywords.Select(kw => new { Keyword = kw, Type = StepKeywordType.Conjunction }))
4747
.GroupBy(item => item.Keyword, item => item.Type)
48-
.ToDictionary(item => item.Key, item => item.First());
48+
// Fold keywords with ambiguous keyword types into unknown
49+
.ToDictionary(item => item.Key, items => items.Count() == 1 ? items.First() : StepKeywordType.Unknown);
4950

5051
public StepKeywordType? GetStepKeywordType(string keyword)
5152
=> StepKeywordTypes.TryGetValue(keyword, out var tokenType) ? tokenType : null;

0 commit comments

Comments
 (0)