Skip to content

Commit

Permalink
feat: add step type to undefinedSnippet
Browse files Browse the repository at this point in the history
  • Loading branch information
crosscode-nl committed Jan 2, 2024
1 parent 348afe7 commit e8d8659
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion internal/snippets/step_func_snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/cucumber/godog/internal/models"
"github.com/cucumber/godog/internal/storage"
messages "github.com/cucumber/messages/go/v21"
"sort"
"strings"
"unicode"
Expand Down Expand Up @@ -32,7 +33,22 @@ func StepFunction(s *storage.Storage) string {
steps = u.Def.Undefined
arg = nil
}

// Not sure if range is needed... don't understand it yet.
for _, step := range steps {
var stepType string

switch pickleStep.Type {
case messages.PickleStepType_ACTION:
stepType = "When"
case messages.PickleStepType_CONTEXT:
stepType = "Given"
case messages.PickleStepType_OUTCOME:
stepType = "Then"
default:
stepType = "Step"
}

expr := snippetExprCleanup.ReplaceAllString(step, "\\$1")
expr = snippetNumbers.ReplaceAllString(expr, "(\\d+)")
expr = snippetExprQuoted.ReplaceAllString(expr, "$1\"([^\"]*)\"$2")
Expand Down Expand Up @@ -65,7 +81,7 @@ func StepFunction(s *storage.Storage) string {
}
}
if !found {
snips = append(snips, undefinedSnippet{Method: name, Expr: expr, argument: arg})
snips = append(snips, undefinedSnippet{Method: name, Type: stepType, Expr: expr, argument: arg})
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/snippets/undefined_snippets_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var undefinedSnippetsTpl = template.Must(template.New("snippets").Funcs(snippetH
type undefinedSnippet struct {
Method string
Expr string
Type string
argument *messages.PickleStepArgument
}

Expand All @@ -44,7 +45,9 @@ func (s undefinedSnippet) Args() (ret string) {
pos int
breakLoop bool
)
/*
*/
for !breakLoop {
part := s.Expr[pos:]
ipos := strings.Index(part, "(\\d+)")
Expand Down

0 comments on commit e8d8659

Please sign in to comment.