Skip to content

Commit 0a6afe5

Browse files
committed
fixed & simplified groovy step snippets
1 parent 2b4685a commit 0a6afe5

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

groovy/src/main/java/cucumber/runtime/groovy/GroovySnippet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class GroovySnippet implements Snippet {
88
@Override
99
public String template() {
10-
return "{0}(~\"{1}\") '{' {3}->\n" +
10+
return "{0}(~''{1}'') '{' {3}->\n" +
1111
" // {4}\n" +
1212
" throw new PendingException()\n" +
1313
"'}'\n";
@@ -46,6 +46,6 @@ public String namedGroupEnd() {
4646

4747
@Override
4848
public String escapePattern(String pattern) {
49-
return pattern.replaceAll("\"", "\\\\\"");
49+
return pattern;
5050
}
5151
}

groovy/src/test/java/cucumber/runtime/groovy/GroovySnippetTest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class GroovySnippetTest {
2020
@Test
2121
public void generatesPlainSnippet() {
2222
String expected = "" +
23-
"Given(~\"^I have (\\d+) cukes in my \\\"([^\\\"]*)\\\" belly$\") { int arg1, String arg2 ->\n" +
23+
"Given(~'^I have (\\d+) cukes in my \"([^\"]*)\" belly$') { int arg1, String arg2 ->\n" +
2424
" // Express the Regexp above with the code you wish you had\n" +
2525
" throw new PendingException()\n" +
2626
"}\n";
@@ -30,7 +30,7 @@ public void generatesPlainSnippet() {
3030
@Test
3131
public void generatesCopyPasteReadyStepSnippetForNumberParameters() throws Exception {
3232
String expected = "" +
33-
"Given(~\"^before (\\d+) after$\") { int arg1 ->\n" +
33+
"Given(~'^before (\\d+) after$') { int arg1 ->\n" +
3434
" // Express the Regexp above with the code you wish you had\n" +
3535
" throw new PendingException()\n" +
3636
"}\n";
@@ -41,7 +41,7 @@ public void generatesCopyPasteReadyStepSnippetForNumberParameters() throws Excep
4141
@Test
4242
public void generatesCopyPasteReadySnippetWhenStepHasIllegalJavaIdentifierChars() {
4343
String expected = "" +
44-
"Given(~\"^I have (\\d+) cukes in: my \\\"([^\\\"]*)\\\" red-belly!$\") { int arg1, String arg2 ->\n" +
44+
"Given(~'^I have (\\d+) cukes in: my \"([^\"]*)\" red-belly!$') { int arg1, String arg2 ->\n" +
4545
" // Express the Regexp above with the code you wish you had\n" +
4646
" throw new PendingException()\n" +
4747
"}\n";
@@ -52,7 +52,7 @@ public void generatesCopyPasteReadySnippetWhenStepHasIllegalJavaIdentifierChars(
5252
@Test
5353
public void generatesCopyPasteReadySnippetWhenStepHasIntegersInsideStringParameter() {
5454
String expected = "" +
55-
"Given(~\"^the DI system receives a message saying \\\"([^\\\"]*)\\\"$\") { String arg1 ->\n" +
55+
"Given(~'^the DI system receives a message saying \"([^\"]*)\"$') { String arg1 ->\n" +
5656
" // Express the Regexp above with the code you wish you had\n" +
5757
" throw new PendingException()\n" +
5858
"}\n";
@@ -62,7 +62,7 @@ public void generatesCopyPasteReadySnippetWhenStepHasIntegersInsideStringParamet
6262
@Test
6363
public void generatesSnippetWithEscapedDollarSigns() {
6464
String expected = "" +
65-
"Given(~\"^I have \\$(\\d+)$\") { int arg1 ->\n" +
65+
"Given(~'^I have \\$(\\d+)$') { int arg1 ->\n" +
6666
" // Express the Regexp above with the code you wish you had\n" +
6767
" throw new PendingException()\n" +
6868
"}\n";
@@ -72,7 +72,7 @@ public void generatesSnippetWithEscapedDollarSigns() {
7272
@Test
7373
public void generatesSnippetWithEscapedParentheses() {
7474
String expected = "" +
75-
"Given(~\"^I have (\\d+) cukes \\(maybe more\\)$\") { int arg1 ->\n" +
75+
"Given(~'^I have (\\d+) cukes \\(maybe more\\)$') { int arg1 ->\n" +
7676
" // Express the Regexp above with the code you wish you had\n" +
7777
" throw new PendingException()\n" +
7878
"}\n";
@@ -82,7 +82,7 @@ public void generatesSnippetWithEscapedParentheses() {
8282
@Test
8383
public void generatesSnippetWithEscapedBrackets() {
8484
String expected = "" +
85-
"Given(~\"^I have (\\d+) cukes \\[maybe more\\]$\") { int arg1 ->\n" +
85+
"Given(~'^I have (\\d+) cukes \\[maybe more\\]$') { int arg1 ->\n" +
8686
" // Express the Regexp above with the code you wish you had\n" +
8787
" throw new PendingException()\n" +
8888
"}\n";
@@ -92,7 +92,7 @@ public void generatesSnippetWithEscapedBrackets() {
9292
@Test
9393
public void generatesSnippetWithDocString() {
9494
String expected = "" +
95-
"Given(~\"^I have:$\") { String arg1 ->\n" +
95+
"Given(~'^I have:$') { String arg1 ->\n" +
9696
" // Express the Regexp above with the code you wish you had\n" +
9797
" throw new PendingException()\n" +
9898
"}\n";
@@ -102,7 +102,7 @@ public void generatesSnippetWithDocString() {
102102
@Test
103103
public void generatesSnippetWithDataTable() {
104104
String expected = "" +
105-
"Given(~\"^I have:$\") { DataTable arg1 ->\n" +
105+
"Given(~'^I have:$') { DataTable arg1 ->\n" +
106106
" // Express the Regexp above with the code you wish you had\n" +
107107
" throw new PendingException()\n" +
108108
"}\n";
@@ -124,4 +124,4 @@ private String snippetForDataTable(String name, List<DataTableRow> dataTable) {
124124
Step step = new Step(NO_COMMENTS, "Given ", name, 0, dataTable, null);
125125
return new SnippetGenerator(new GroovySnippet()).getSnippet(step);
126126
}
127-
}
127+
}

0 commit comments

Comments
 (0)