Skip to content

Commit 43776a3

Browse files
authored
Merge pull request #1078 from avokin/snippet-for-outline-param
SnippetGenerator recognises parameters from Scenario Outline (<param>)
2 parents 1bef648 + 2d51e5d commit 43776a3

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

core/src/main/java/cucumber/runtime/snippets/ArgumentPattern.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ public class ArgumentPattern {
77

88
private final Pattern pattern;
99
private final Class<?> type;
10+
private final String replacement;
1011

1112
public ArgumentPattern(Pattern pattern, Class<?> type) {
13+
this(pattern, pattern.pattern(), type);
14+
}
15+
16+
public ArgumentPattern(Pattern pattern, String replacement, Class<?> type) {
1217
this.pattern = pattern;
18+
this.replacement = replacement;
1319
this.type = type;
1420
}
1521

@@ -22,7 +28,7 @@ public Class<?> type() {
2228
}
2329

2430
public String replaceMatchesWithGroups(String name) {
25-
return replaceMatchWith(name, pattern.pattern());
31+
return replaceMatchWith(name, replacement);
2632
}
2733

2834
public String replaceMatchesWithSpace(String name) {

core/src/main/java/cucumber/runtime/snippets/SnippetGenerator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
public class SnippetGenerator {
1616
private static final ArgumentPattern[] DEFAULT_ARGUMENT_PATTERNS = new ArgumentPattern[]{
1717
new ArgumentPattern(Pattern.compile("\"([^\"]*)\""), String.class),
18-
new ArgumentPattern(Pattern.compile("(\\d+)"), Integer.TYPE)
18+
new ArgumentPattern(Pattern.compile("(\\d+)"), Integer.TYPE),
19+
new ArgumentPattern(Pattern.compile("<([^>]*)>"), "(.*)", String.class)
1920
};
2021
private static final Pattern GROUP_PATTERN = Pattern.compile("\\(");
2122
private static final Pattern[] ESCAPE_PATTERNS = new Pattern[]{

java/src/test/java/cucumber/runtime/java/JavaSnippetTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ public void generatesSnippetWithDataTable() {
160160
assertEquals(expected, snippetForDataTable("I have:", dataTable));
161161
}
162162

163+
@Test
164+
public void generateSnippetWithOutlineParam() {
165+
String expected = "" +
166+
"@Given(\"^Then it responds (.*)$\")\n" +
167+
"public void then_it_responds(String arg1) throws Throwable {\n" +
168+
" // Write code here that turns the phrase above into concrete actions\n" +
169+
" throw new PendingException();\n" +
170+
"}\n";
171+
172+
assertEquals(expected, snippetFor("Then it responds <param>"));
173+
}
174+
163175
private String snippetFor(String name) {
164176
PickleStep step = new PickleStep(name, Collections.<Argument>emptyList(), Collections.<PickleLocation>emptyList());
165177
return new SnippetGenerator(new JavaSnippet()).getSnippet(step, GIVEN_KEYWORD, functionNameGenerator);

0 commit comments

Comments
 (0)