From 0a6afe5f29e3e5a9575dd11742dd849e37452c2c Mon Sep 17 00:00:00 2001 From: Martin Hauner Date: Sat, 21 Apr 2012 12:06:38 +0200 Subject: [PATCH] fixed & simplified groovy step snippets --- .../runtime/groovy/GroovySnippet.java | 4 ++-- .../runtime/groovy/GroovySnippetTest.java | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/groovy/src/main/java/cucumber/runtime/groovy/GroovySnippet.java b/groovy/src/main/java/cucumber/runtime/groovy/GroovySnippet.java index e9c3fe3ac5..bdadf51edb 100644 --- a/groovy/src/main/java/cucumber/runtime/groovy/GroovySnippet.java +++ b/groovy/src/main/java/cucumber/runtime/groovy/GroovySnippet.java @@ -7,7 +7,7 @@ public class GroovySnippet implements Snippet { @Override public String template() { - return "{0}(~\"{1}\") '{' {3}->\n" + + return "{0}(~''{1}'') '{' {3}->\n" + " // {4}\n" + " throw new PendingException()\n" + "'}'\n"; @@ -46,6 +46,6 @@ public String namedGroupEnd() { @Override public String escapePattern(String pattern) { - return pattern.replaceAll("\"", "\\\\\""); + return pattern; } } diff --git a/groovy/src/test/java/cucumber/runtime/groovy/GroovySnippetTest.java b/groovy/src/test/java/cucumber/runtime/groovy/GroovySnippetTest.java index a6a0f7752e..0c9ed748da 100644 --- a/groovy/src/test/java/cucumber/runtime/groovy/GroovySnippetTest.java +++ b/groovy/src/test/java/cucumber/runtime/groovy/GroovySnippetTest.java @@ -20,7 +20,7 @@ public class GroovySnippetTest { @Test public void generatesPlainSnippet() { String expected = "" + - "Given(~\"^I have (\\d+) cukes in my \\\"([^\\\"]*)\\\" belly$\") { int arg1, String arg2 ->\n" + + "Given(~'^I have (\\d+) cukes in my \"([^\"]*)\" belly$') { int arg1, String arg2 ->\n" + " // Express the Regexp above with the code you wish you had\n" + " throw new PendingException()\n" + "}\n"; @@ -30,7 +30,7 @@ public void generatesPlainSnippet() { @Test public void generatesCopyPasteReadyStepSnippetForNumberParameters() throws Exception { String expected = "" + - "Given(~\"^before (\\d+) after$\") { int arg1 ->\n" + + "Given(~'^before (\\d+) after$') { int arg1 ->\n" + " // Express the Regexp above with the code you wish you had\n" + " throw new PendingException()\n" + "}\n"; @@ -41,7 +41,7 @@ public void generatesCopyPasteReadyStepSnippetForNumberParameters() throws Excep @Test public void generatesCopyPasteReadySnippetWhenStepHasIllegalJavaIdentifierChars() { String expected = "" + - "Given(~\"^I have (\\d+) cukes in: my \\\"([^\\\"]*)\\\" red-belly!$\") { int arg1, String arg2 ->\n" + + "Given(~'^I have (\\d+) cukes in: my \"([^\"]*)\" red-belly!$') { int arg1, String arg2 ->\n" + " // Express the Regexp above with the code you wish you had\n" + " throw new PendingException()\n" + "}\n"; @@ -52,7 +52,7 @@ public void generatesCopyPasteReadySnippetWhenStepHasIllegalJavaIdentifierChars( @Test public void generatesCopyPasteReadySnippetWhenStepHasIntegersInsideStringParameter() { String expected = "" + - "Given(~\"^the DI system receives a message saying \\\"([^\\\"]*)\\\"$\") { String arg1 ->\n" + + "Given(~'^the DI system receives a message saying \"([^\"]*)\"$') { String arg1 ->\n" + " // Express the Regexp above with the code you wish you had\n" + " throw new PendingException()\n" + "}\n"; @@ -62,7 +62,7 @@ public void generatesCopyPasteReadySnippetWhenStepHasIntegersInsideStringParamet @Test public void generatesSnippetWithEscapedDollarSigns() { String expected = "" + - "Given(~\"^I have \\$(\\d+)$\") { int arg1 ->\n" + + "Given(~'^I have \\$(\\d+)$') { int arg1 ->\n" + " // Express the Regexp above with the code you wish you had\n" + " throw new PendingException()\n" + "}\n"; @@ -72,7 +72,7 @@ public void generatesSnippetWithEscapedDollarSigns() { @Test public void generatesSnippetWithEscapedParentheses() { String expected = "" + - "Given(~\"^I have (\\d+) cukes \\(maybe more\\)$\") { int arg1 ->\n" + + "Given(~'^I have (\\d+) cukes \\(maybe more\\)$') { int arg1 ->\n" + " // Express the Regexp above with the code you wish you had\n" + " throw new PendingException()\n" + "}\n"; @@ -82,7 +82,7 @@ public void generatesSnippetWithEscapedParentheses() { @Test public void generatesSnippetWithEscapedBrackets() { String expected = "" + - "Given(~\"^I have (\\d+) cukes \\[maybe more\\]$\") { int arg1 ->\n" + + "Given(~'^I have (\\d+) cukes \\[maybe more\\]$') { int arg1 ->\n" + " // Express the Regexp above with the code you wish you had\n" + " throw new PendingException()\n" + "}\n"; @@ -92,7 +92,7 @@ public void generatesSnippetWithEscapedBrackets() { @Test public void generatesSnippetWithDocString() { String expected = "" + - "Given(~\"^I have:$\") { String arg1 ->\n" + + "Given(~'^I have:$') { String arg1 ->\n" + " // Express the Regexp above with the code you wish you had\n" + " throw new PendingException()\n" + "}\n"; @@ -102,7 +102,7 @@ public void generatesSnippetWithDocString() { @Test public void generatesSnippetWithDataTable() { String expected = "" + - "Given(~\"^I have:$\") { DataTable arg1 ->\n" + + "Given(~'^I have:$') { DataTable arg1 ->\n" + " // Express the Regexp above with the code you wish you had\n" + " throw new PendingException()\n" + "}\n"; @@ -124,4 +124,4 @@ private String snippetForDataTable(String name, List dataTable) { Step step = new Step(NO_COMMENTS, "Given ", name, 0, dataTable, null); return new SnippetGenerator(new GroovySnippet()).getSnippet(step); } -} \ No newline at end of file +}