Skip to content

Commit

Permalink
JBEHAVE-1592 Fix parsing of Lifecycle steps on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst authored Nov 16, 2023
1 parent ff32dfb commit 7f06883
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected List<String> findSteps(String stepsAsText) {
private Pattern findingSteps() {
String startingWords = concatenateStartingWords();
return compile(
"((" + startingWords + ")(.*?))(\\Z|" + startingWords + "|\\n" + keywords().examplesTable() + ")",
"((" + startingWords + ")(.*?))(\\Z|" + startingWords + "|" + CRLF + keywords().examplesTable() + ")",
DOTALL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -36,6 +37,8 @@
import org.jbehave.core.model.Story;
import org.jbehave.core.model.TableTransformers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

class RegexStoryParserBehaviour {

Expand Down Expand Up @@ -543,6 +546,31 @@ void shouldParseStoryWithLifecycleExamplesOnly() {
assertThat(steps.get(0), equalTo("Given a scenario"));
}

@ParameterizedTest
@ValueSource(strings = {NL, "\r\n"})
void shouldParseStoryWithLifecycleStepsAndExamples(String lineEnding) {
String wholeStory = "Lifecycle: "
+ lineEnding + "Before:"
+ lineEnding + "Scope: STORY"
+ lineEnding + "Given a step before story"
+ lineEnding + "Examples:"
+ lineEnding + "|header|"
+ lineEnding + "|value|"
+ lineEnding + "Scenario:"
+ lineEnding + "Given a scenario";
Story story = parser.parseStory(wholeStory, storyPath);
Lifecycle lifecycle = story.getLifecycle();
assertThat(lifecycle.getBeforeSteps(Scope.STORY), equalTo(singletonList("Given a step before story")));
ExamplesTable table = lifecycle.getExamplesTable();
assertThat(table.asString(), equalTo(
"|header|"
+ NL + "|value|"
+ NL));
Scenario scenario = story.getScenarios().get(0);
List<String> steps = scenario.getSteps();
assertThat(steps.get(0), equalTo("Given a scenario"));
}

@Test
void shouldParseStoryWithLifecycleAfterUponOutcomeInNonEnglishLocale() {
String wholeStory = "Lebenszyklus: "
Expand Down

0 comments on commit 7f06883

Please sign in to comment.