Код генерится с именами параметров (шаблонных примеров)
Этот коммит содержится в:
родитель
93631bcb0a
коммит
9f9f9453dc
4 изменённых файлов: 90 добавлений и 11 удалений
|
@ -153,22 +153,24 @@ Feature: undefined step snippets
|
|||
|
||||
Сценарий: делает что-то полезное
|
||||
Дано что-то
|
||||
Когда я делаю ещё что-то
|
||||
Когда я делаю ещё что-то "<param1>", 1, 2, param="<param2>", "<параметр3>", "just string", "<data>"
|
||||
То получается ещё более что-то
|
||||
Примеры:
|
||||
|param1|param2|параметр3|data|
|
||||
|--- |--- |--- |--- |
|
||||
"""
|
||||
When I run feature suite
|
||||
Then the following steps should be undefined:
|
||||
"""
|
||||
получается ещё более что-то
|
||||
что-то
|
||||
я делаю ещё что-то
|
||||
"""
|
||||
And the undefined step snippets should be:
|
||||
"""
|
||||
func чтото() {
|
||||
}
|
||||
|
||||
func яДелаюЕщёЧтото() {
|
||||
func яДелаюЕщёЧтотоParam(param1 string, arg1, arg2 int, param2, параметр3, arg3, data string) {
|
||||
}
|
||||
|
||||
func получаетсяЕщёБолееЧтото() {
|
||||
|
@ -176,7 +178,7 @@ Feature: undefined step snippets
|
|||
|
||||
func InitializeScenario(ctx *godog.ScenarioContext) {
|
||||
ctx.Step(`^что-то$`, чтото)
|
||||
ctx.Step(`^я делаю ещё что-то$`, яДелаюЕщёЧтото)
|
||||
ctx.Step(`^я делаю ещё что-то "([^"]*)", (\d+), (\d+), param="([^"]*)", "([^"]*)", "([^"]*)", "([^"]*)"$`, яДелаюЕщёЧтотоParam)
|
||||
ctx.Step(`^получается ещё более что-то$`, получаетсяЕщёБолееЧтото)
|
||||
}
|
||||
"""
|
||||
|
|
|
@ -215,7 +215,6 @@ func (f *Base) Snippets() string {
|
|||
// build snippets
|
||||
for _, u := range undefinedStepResults {
|
||||
pickleStep := f.Storage.MustGetPickleStep(u.PickleStepID)
|
||||
|
||||
steps := []string{pickleStep.Text}
|
||||
arg := pickleStep.Argument
|
||||
if u.Def != nil {
|
||||
|
@ -257,7 +256,12 @@ func (f *Base) Snippets() string {
|
|||
}
|
||||
}
|
||||
if !found {
|
||||
snips = append(snips, undefinedSnippet{Method: name, Expr: expr, argument: arg})
|
||||
snips = append(snips, undefinedSnippet{
|
||||
Method: name,
|
||||
Expr: expr,
|
||||
argument: arg,
|
||||
argument_names: f.get_argument_names(&u, pickleStep),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -269,3 +273,58 @@ func (f *Base) Snippets() string {
|
|||
// there may be trailing spaces
|
||||
return strings.Replace(buf.String(), " \n", "\n", -1)
|
||||
}
|
||||
|
||||
func (f *Base) get_argument_names(undefResult *models.PickleStepResult, pickleStep *messages.PickleStep) (arg_names map[int]string) {
|
||||
step := f.find_undef_step(undefResult, pickleStep)
|
||||
if step == nil {
|
||||
return
|
||||
}
|
||||
|
||||
arg_names = map[int]string{}
|
||||
|
||||
args := snippetExprAnyParam.FindAllString(step.Text, -1)
|
||||
for i, a := range args {
|
||||
a = strings.TrimSpace(a)
|
||||
|
||||
if len(a) < 5 {
|
||||
continue
|
||||
}
|
||||
|
||||
parts := strings.Split(a, "\"")
|
||||
if len(parts) < 3 {
|
||||
continue
|
||||
}
|
||||
a = parts[1]
|
||||
|
||||
if a[0] != '<' {
|
||||
continue
|
||||
}
|
||||
|
||||
a = a[1 : len(a)-1]
|
||||
|
||||
// fmt.Printf("\ta: %v: %v\n", a, parts)
|
||||
|
||||
arg_names[i] = a
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
func (f *Base) find_undef_step(undefResult *models.PickleStepResult, pickleStep *messages.PickleStep) *messages.Step {
|
||||
pickle := f.Storage.MustGetPickle(undefResult.PickleID)
|
||||
if pickle == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
feat := f.Storage.MustGetFeature(pickle.Uri)
|
||||
if feat == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(pickleStep.AstNodeIds) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
step_id := pickleStep.AstNodeIds[0]
|
||||
|
||||
return feat.FindStep(step_id)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
// some snippet formatting regexps
|
||||
var snippetExprCleanup = regexp.MustCompile(`([\/\[\]\(\)\\^\$\.\|\?\*\+\'])`)
|
||||
var snippetExprQuoted = regexp.MustCompile(`(\W|^)"(?:[^"]*)"(\W|$)`)
|
||||
var snippetExprAnyParam = regexp.MustCompile("(\\W|^)((\\d+)|\"(?:[^\"]*)\")(\\W|$)")
|
||||
var snippetMethodName = regexp.MustCompile("[^a-zA-Zа-яА-ЯёЁ\\_\\ ]")
|
||||
var snippetNumbers = regexp.MustCompile(`(\d+)`)
|
||||
|
||||
|
@ -32,9 +33,10 @@ var undefinedSnippetsTpl = template.Must(template.New("snippets").Funcs(snippetH
|
|||
`))
|
||||
|
||||
type undefinedSnippet struct {
|
||||
Method string
|
||||
Expr string
|
||||
argument *messages.PickleStepArgument
|
||||
Method string
|
||||
Expr string
|
||||
argument *messages.PickleStepArgument
|
||||
argument_names map[int]string
|
||||
}
|
||||
|
||||
func (s undefinedSnippet) Args() (ret string) {
|
||||
|
@ -79,11 +81,25 @@ func (s undefinedSnippet) Args() (ret string) {
|
|||
|
||||
var last string
|
||||
|
||||
// fmt.Printf(" \tArgs: names: %v\n", s.argument_names)
|
||||
|
||||
arg_ind := 0
|
||||
for i, arg := range args {
|
||||
name, ok := s.argument_names[i]
|
||||
if last == "" || last == arg {
|
||||
ret += fmt.Sprintf("arg%d, ", i+1)
|
||||
if ok {
|
||||
ret += fmt.Sprintf("%v, ", name)
|
||||
} else {
|
||||
arg_ind++
|
||||
ret += fmt.Sprintf("arg%d, ", arg_ind)
|
||||
}
|
||||
} else {
|
||||
ret = strings.TrimRight(ret, ", ") + fmt.Sprintf(" %s, arg%d, ", last, i+1)
|
||||
if ok {
|
||||
ret = strings.TrimRight(ret, ", ") + fmt.Sprintf(" %s, %v, ", last, name)
|
||||
} else {
|
||||
arg_ind++
|
||||
ret = strings.TrimRight(ret, ", ") + fmt.Sprintf(" %s, arg%d, ", last, arg_ind)
|
||||
}
|
||||
}
|
||||
|
||||
last = arg
|
||||
|
|
|
@ -270,6 +270,8 @@ func (tc *godogFeaturesScenario) iRunFeatureSuiteWithFormatter(name string) erro
|
|||
}
|
||||
|
||||
func (tc *godogFeaturesScenario) iRunFeatureSuiteWithTagsAndFormatter(filter string, fmtFunc FormatterFunc) error {
|
||||
// Entry point for tested feature
|
||||
|
||||
if err := tc.parseFeatures(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче