Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fixed #391, groovy step snippet escaping #400

Merged
merged 2 commits into from

2 participants

@hauner

No description provided.

@aslakhellesoy aslakhellesoy merged commit 06a5333 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 6, 2012
  1. @hauner

    fix cucumber-jvm #391

    hauner authored
Commits on Oct 7, 2012
  1. @hauner
This page is out of date. Refresh to see the latest.
View
2  groovy/src/main/java/cucumber/runtime/groovy/GroovySnippet.java
@@ -46,6 +46,6 @@ public String namedGroupEnd() {
@Override
public String escapePattern(String pattern) {
- return pattern;
+ return pattern.replace ("\\", "\\\\");
}
}
View
23 groovy/src/test/java/cucumber/runtime/groovy/GroovySnippetTest.java
@@ -20,7 +20,7 @@
@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";
@@ -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";
@@ -110,6 +110,17 @@ public void generatesSnippetWithDataTable() {
assertEquals(expected, snippetForDataTable("I have:", dataTable));
}
+ @Test
+ public void generateSnippetWithEscapedEscapeCharacter() {
+ String expected = "" +
+ "Given(~'^I have (\\\\d+) cukes in my belly$') { int arg1 ->\n" +
+ " // Express the Regexp above with the code you wish you had\n" +
+ " throw new PendingException()\n" +
+ "}\n";
+
+ assertEquals(expected, snippetFor("I have 4 cukes in my belly"));
+ }
+
private String snippetFor(String name) {
Step step = new Step(NO_COMMENTS, "Given ", name, 0, null, null);
return new SnippetGenerator(new GroovySnippet()).getSnippet(step);
Something went wrong with that request. Please try again.