1 Star 0 Fork 0

blackbelly / gherkingen

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
std.struct.v1.go.tmpl 3.52 KB
一键复制 编辑 原始数据 按行查看 历史
package {{ .PackageName }}
import (
"testing"
"github.com/hedhyw/gherkingen/v3/pkg/bdd"
)
{{ define "Background" }}
{{- $Background := . -}}
background := func(t *testing.T, f *bdd.Feature) interface{} {
/* TODO: Feel free to modify return value(s). */
{{- range $Background.Steps }}
f.{{ .PluginData.GoName }}({{.PluginData.GoValue}}, func() {
})
{{- end }}
return nil
}
{{ end }}
{{ define "Scenario" }}
{{- $Scenario := . -}}
f.{{ $Scenario.PluginData.GoName }}({{ $Scenario.PluginData.GoValue }}, func({{- /*
t is usualy unused if there are no examples
*/ -}}{{- if and $Scenario.Examples (not $Scenario.PluginData.GoParallel) -}}_{{- else -}}t{{- end -}} *testing.T, f *bdd.Feature) {
{{- range $Scenario.Examples }}
{{- if $Scenario.PluginData.GoParallel }}
t.Parallel()
{{ end -}}
{{- /* Define test case struct. */ -}}
type testCase struct {
{{- range .TableHeader.Cells }}
{{ .PluginData.GoName }} {{ .PluginData.GoType }} `field:"{{.Value}}"`
{{- end -}}
}
testCases := map[string]testCase{
{{- range .TableBody }}
{{ .PluginData.GoValue }}: {
{{- /* Struct fields start. */ -}}
{{- range $index, $cell := .Cells -}}
{{- if $index -}},{{ end }} {{- $cell.PluginData.GoValue -}}
{{- end -}}
{{- /* Struct fields end. */ -}}
},
{{- end }}
}
f.TestCases(testCases, func(t *testing.T, f *bdd.Feature, tc testCase) {
{{- if $Scenario.PluginData.GoParallel }}
t.Parallel()
{{ end -}}
{{- if $Scenario.PluginData.GoHasBackground }}
_ = background(t, f)
{{ end -}}
{{- range $Scenario.Steps }}
f.{{ .PluginData.GoName }}({{ .PluginData.GoValue }}, func() {
})
{{- end }}
})
{{- else }}
{{- if $Scenario.PluginData.GoParallel }}
t.Parallel()
{{ end -}}
{{- if $Scenario.PluginData.GoHasBackground }}
_ = background(t, f)
{{ end }}
{{- range $Scenario.Steps }}
f.{{ .PluginData.GoName }}({{.PluginData.GoValue}}, func() {
})
{{- end -}}
{{ end }}
})
{{ end }}
{{ define "Rule" }}
{{ $Rule := . }}
f.{{ $Rule.PluginData.GoName }}({{ $Rule.PluginData.GoValue }}, func({{- if $Rule.PluginData.GoParallel -}}t{{- else -}}_{{- end -}} *testing.T, f *bdd.Feature) {
{{- if $Rule.PluginData.GoParallel }}
t.Parallel()
{{ end -}}
{{- range $Rule.Children -}}
{{- if .Background }}
{{ template "Background" .Background }}
{{- end }}
{{- if .Scenario }}
{{- template "Scenario" .Scenario -}}
{{- end }}
{{- end -}}
})
{{ end }}
func Test{{ .Feature.PluginData.GoName }}(t *testing.T) {
{{- if .Feature.PluginData.GoParallel }}
t.Parallel()
{{ end -}}
f := bdd.NewFeature(t, {{ .Feature.PluginData.GoValue }})
{{ if .Feature.PluginData.GoComment }}
/* {{ .Feature.PluginData.GoComment | withFinalDot }} */
{{ end }}
{{- range .Feature.Children }}
{{ if .Background }}
{{ template "Background" .Background }}
{{- end -}}
{{ if .Scenario }}
{{ template "Scenario" .Scenario }}
{{- end -}}
{{ if .Rule }}
{{ template "Rule" .Rule }}
{{- end -}}
{{- end -}}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/blackbelly/gherkingen.git
git@gitee.com:blackbelly/gherkingen.git
blackbelly
gherkingen
gherkingen
d0276da9c2e5

搜索帮助

344bd9b3 5694891 D2dac590 5694891