Skip to content

Commit

Permalink
ReqnrollGherkinDialectProvider: Avoid NoSuchLanguageException
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron committed Nov 27, 2024
1 parent eef7876 commit 65969ec
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions Reqnroll/Parser/ReqnrollGherkinDialectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ public override GherkinDialect GetDialect(string language, Location location)
{
if (language.Contains("-"))
{
try
{
return base.GetDialect(language, location);
}
catch (NoSuchLanguageException)
{
var languageBase = language.Split('-')[0];
var languageBaseDialect = base.GetDialect(languageBase, location);
return new GherkinDialect(language, languageBaseDialect.FeatureKeywords, languageBaseDialect.RuleKeywords, languageBaseDialect.BackgroundKeywords, languageBaseDialect.ScenarioKeywords, languageBaseDialect.ScenarioOutlineKeywords, languageBaseDialect.ExamplesKeywords, languageBaseDialect.GivenStepKeywords, languageBaseDialect.WhenStepKeywords, languageBaseDialect.ThenStepKeywords, languageBaseDialect.AndStepKeywords, languageBaseDialect.ButStepKeywords);
}
// Use TryGetDialect to avoid NoSuchLanguageException, if culture specific language is not present
if (TryGetDialect(language, location, out var dialect))
return dialect;

var languageBase = language.Split('-')[0];
var languageBaseDialect = base.GetDialect(languageBase, location);
return new GherkinDialect(language, languageBaseDialect.FeatureKeywords, languageBaseDialect.RuleKeywords, languageBaseDialect.BackgroundKeywords, languageBaseDialect.ScenarioKeywords, languageBaseDialect.ScenarioOutlineKeywords, languageBaseDialect.ExamplesKeywords, languageBaseDialect.GivenStepKeywords, languageBaseDialect.WhenStepKeywords, languageBaseDialect.ThenStepKeywords, languageBaseDialect.AndStepKeywords, languageBaseDialect.ButStepKeywords);
}

return base.GetDialect(language, location);
Expand Down

0 comments on commit 65969ec

Please sign in to comment.