diff --git a/CHANGELOG.md b/CHANGELOG.md index 14caee63..f373c4c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,11 @@ ## Improvements: +* Update autoformatting to replace sequential equivalent keywords with the `And` keyword + ## Bug fixes: -*Contributors of this release (in alphabetical order):* +*Contributors of this release (in alphabetical order):* @jdb0123 # v2024.8.234 - 2025-01-22 diff --git a/Reqnroll.VisualStudio/Editor/Services/Formatting/GherkinDocumentFormatter.cs b/Reqnroll.VisualStudio/Editor/Services/Formatting/GherkinDocumentFormatter.cs index b24d9d01..0a31b5a6 100644 --- a/Reqnroll.VisualStudio/Editor/Services/Formatting/GherkinDocumentFormatter.cs +++ b/Reqnroll.VisualStudio/Editor/Services/Formatting/GherkinDocumentFormatter.cs @@ -8,16 +8,15 @@ public class GherkinDocumentFormatter public void FormatGherkinDocument(DeveroomGherkinDocument gherkinDocument, DocumentLinesEditBuffer lines, GherkinFormatSettings formatSettings) { - if (gherkinDocument.Feature != null) - { - SetTagsAndLine(lines, gherkinDocument.Feature, string.Empty); - SetLinesForChildren(lines, gherkinDocument.Feature.Children, formatSettings, - formatSettings.FeatureChildrenIndentLevel); - } + if (gherkinDocument.Feature == null) + return; + + SetTagsAndLine(lines, gherkinDocument.Feature, string.Empty); + SetLinesForChildren(lines, gherkinDocument.Feature.Children, formatSettings, formatSettings.FeatureChildrenIndentLevel, gherkinDocument.GherkinDialect); } private void SetLinesForChildren(DocumentLinesEditBuffer lines, IEnumerable hasLocation, - GherkinFormatSettings formatSettings, int indentLevel) + GherkinFormatSettings formatSettings, int indentLevel, GherkinDialect gherkinDialect) { foreach (var featureChild in hasLocation) { @@ -25,7 +24,7 @@ private void SetLinesForChildren(DocumentLinesEditBuffer lines, IEnumerable keyword != GherkinDialect.AsteriskKeyword); } private void SetTagsAndLine(DocumentLinesEditBuffer lines, IHasLocation hasLocation, string indent) diff --git a/Tests/Reqnroll.VisualStudio.Specs/Features/Editor/Commands/AutoFormatDocumentCommand.feature b/Tests/Reqnroll.VisualStudio.Specs/Features/Editor/Commands/AutoFormatDocumentCommand.feature index 08318d2e..ee463ead 100644 --- a/Tests/Reqnroll.VisualStudio.Specs/Features/Editor/Commands/AutoFormatDocumentCommand.feature +++ b/Tests/Reqnroll.VisualStudio.Specs/Features/Editor/Commands/AutoFormatDocumentCommand.feature @@ -301,4 +301,35 @@ Scenario: Formatting of Descriptions and Comments are not changed Todo: handle negative numbers Given I have entered 50 into the calculator + """ + +Rule: Auto format should replace repeated keywords with "And" + +Scenario: Repeating keywords are replaced with "And" + + Given there is a Reqnroll project scope + And the following feature file in the editor + """ + Feature: Addition + + Scenario: Add two numbers + Given I have entered 50 into the calculator + Given I have entered 70 into the calculator + When I add them + When I check the result + Then there should be no error + Then the result should be 120 + """ + When I invoke the "Auto Format Document" command without waiting for the tag changes + Then the editor should be updated to + """ + Feature: Addition + + Scenario: Add two numbers + Given I have entered 50 into the calculator + And I have entered 70 into the calculator + When I add them + And I check the result + Then there should be no error + And the result should be 120 """ \ No newline at end of file