From c302697f9e8e58bdf1880426f392b62384cf6429 Mon Sep 17 00:00:00 2001 From: gedi Date: Tue, 20 Sep 2016 15:21:08 +0300 Subject: [PATCH] fix snippet string argument extraction followed by non space character --- features/snippets.feature | 26 ++++++++++++++++++++++++++ fmt.go | 6 ++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/features/snippets.feature b/features/snippets.feature index af1a9e0..773b2a9 100644 --- a/features/snippets.feature +++ b/features/snippets.feature @@ -92,3 +92,29 @@ Feature: undefined step snippets s.Step(`^the project should be there$`, theProjectShouldBeThere) } """ + + Scenario: should handle string argument followed by comma + Given a feature "undefined.feature" file: + """ + Feature: undefined + + Scenario: add item to basket + Given there is a "Sith Lord Lightsaber", which costs £5 + When I add the "Sith Lord Lightsaber" to the basket + """ + When I run feature suite + And the undefined step snippets should be: + """ + func thereIsAWhichCosts(arg1 string, arg2 int) error { + return godog.ErrPending + } + + func iAddTheToTheBasket(arg1 string) error { + return godog.ErrPending + } + + func FeatureContext(s *godog.Suite) { + s.Step(`^there is a "([^"]*)", which costs £(\d+)$`, thereIsAWhichCosts) + s.Step(`^I add the "([^"]*)" to the basket$`, iAddTheToTheBasket) + } + """ diff --git a/fmt.go b/fmt.go index 172d10f..ce062df 100644 --- a/fmt.go +++ b/fmt.go @@ -15,7 +15,9 @@ import ( // some snippet formatting regexps var snippetExprCleanup = regexp.MustCompile("([\\/\\[\\]\\(\\)\\\\^\\$\\.\\|\\?\\*\\+\\'])") -var snippetExprQuoted = regexp.MustCompile("(\\s*|^)\"(?:[^\"]*)\"(\\s+|$)") + +// var snippetExprQuoted = regexp.MustCompile("(\\s*|^)\"(?:[^\"]*)\"(\\s+|,|:|\\.|$)") +var snippetExprQuoted = regexp.MustCompile("(\\W|^)\"(?:[^\"]*)\"(\\W|$)") var snippetMethodName = regexp.MustCompile("[^a-zA-Z\\_\\ ]") var snippetNumbers = regexp.MustCompile("(\\d+)") @@ -346,7 +348,7 @@ func (f *basefmt) snippets() string { for _, u := range f.undefined { expr := snippetExprCleanup.ReplaceAllString(u.step.Text, "\\$1") expr = snippetNumbers.ReplaceAllString(expr, "(\\d+)") - expr = snippetExprQuoted.ReplaceAllString(expr, " \"([^\"]*)\" ") + expr = snippetExprQuoted.ReplaceAllString(expr, "$1\"([^\"]*)\"$2") expr = "^" + strings.TrimSpace(expr) + "$" name := snippetNumbers.ReplaceAllString(u.step.Text, " ")