- Revision
- 980
- Author
- mauro
- Date
- 2008-10-16 16:44:22 -0500 (Thu, 16 Oct 2008)
Log Message
JBEHAVE-138: Applied patch from Alexandre Martins.
Modified Paths
Diff
Modified: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/parser/PatternScenarioParserBehaviour.java (979 => 980)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/parser/PatternScenarioParserBehaviour.java 2008-10-16 20:08:03 UTC (rev 979) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/parser/PatternScenarioParserBehaviour.java 2008-10-16 21:44:22 UTC (rev 980) @@ -1,7 +1,7 @@ package org.jbehave.scenario.parser; import static org.hamcrest.CoreMatchers.equalTo; -import static org.jbehave.util.JUnit4Ensure.ensureThat; +import static org.jbehave.Ensure.ensureThat; import java.util.Arrays; import java.util.List; @@ -30,6 +30,22 @@ } @Test + public void shouldExtractGivensWhensAndThensFromSimpleScenariosContainingKeywordsAsPartOfTheContent() { + ScenarioParser parser = new PatternScenarioParser(new PropertyBasedConfiguration()); + StoryDefinition story = parser.defineStoryFrom( + "Given a scenario Givenly" + NL + + "When I parse it to Whenever" + NL + + "And I parse it to Anderson" + NL + + "Then I should get steps Thenact"); + + List<String> steps = story.getScenarios().get(0).getSteps(); + ensureThat(steps.get(0), equalTo("Given a scenario Givenly")); + ensureThat(steps.get(1), equalTo("When I parse it to Whenever")); + ensureThat(steps.get(2), equalTo("And I parse it to Anderson")); + ensureThat(steps.get(3), equalTo("Then I should get steps Thenact")); + } + + @Test public void shouldExtractGivensWhensAndThensFromMultilineScenarios() { ScenarioParser parser = new PatternScenarioParser(new PropertyBasedConfiguration()); StoryDefinition story = parser.defineStoryFrom(
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/parser/PatternScenarioParser.java (979 => 980)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/parser/PatternScenarioParser.java 2008-10-16 20:08:03 UTC (rev 979) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/parser/PatternScenarioParser.java 2008-10-16 21:44:22 UTC (rev 980) @@ -96,20 +96,33 @@ } private String concatenateWithOr(String given, String when, String then, String[] others) { + return concatenateWithOr(false, given, when, then, others); + } + + private String concatenateWithSpaceOr(String given, String when, String then, String[] others) { + return concatenateWithOr(true, given, when, then, others); + } + + private String concatenateWithOr(boolean usingSpace, String given, String when, String then, String[] others) { StringBuilder builder = new StringBuilder(); - builder.append(given).append("|"); - builder.append(when).append("|"); - builder.append(then).append("|"); - return builder.append(concatenateWithOr(others)).toString(); + builder.append(given).append(usingSpace ? "\\s|" : "|"); + builder.append(when).append(usingSpace ? "\\s|" : "|"); + builder.append(then).append(usingSpace ? "\\s|" : "|"); + builder.append(usingSpace ? concatenateWithSpaceOr(others) : concatenateWithOr(others)); + return builder.toString(); } private String concatenateWithOr(String... keywords) { - return concatenateWithOr(new StringBuilder(), keywords); + return concatenateWithOr(false, new StringBuilder(), keywords); } + + private String concatenateWithSpaceOr(String... keywords) { + return concatenateWithOr(true, new StringBuilder(), keywords); + } - private String concatenateWithOr(StringBuilder builder, String[] keywords) { + private String concatenateWithOr(boolean usingSpace, StringBuilder builder, String[] keywords) { for (String other : keywords) { - builder.append(other).append("|"); + builder.append(other).append(usingSpace ? "\\s|" : "|"); } String result = builder.toString(); return result.substring(0, result.length() - 1); // chop off the last | @@ -118,7 +131,9 @@ private Pattern patternToPullOutSteps() { String givenWhenThen = concatenateWithOr(configuration.keywords().given(), configuration.keywords().when(), configuration.keywords().then(), configuration.keywords().others()); - return Pattern.compile("((" + givenWhenThen + ") (.|\\s)*?)\\s*(\\Z|" + givenWhenThen + "|" + String givenWhenThenSpaced = concatenateWithSpaceOr(configuration.keywords().given(), configuration.keywords().when(), + configuration.keywords().then(), configuration.keywords().others()); + return Pattern.compile("((" + givenWhenThen + ") (.|\\s)*?)\\s*(\\Z|" + givenWhenThenSpaced + "|" + configuration.keywords().scenario() + ":)"); } }
To unsubscribe from this list please visit:
