-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstd.struct.v1.go.tmpl
133 lines (104 loc) · 3.52 KB
/
std.struct.v1.go.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package {{ .PackageName }}
import (
"testing"
"github.com/hedhyw/gherkingen/v2/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 -}}
{{- range $Scenario.Steps }}
f.{{ .PluginData.GoName }}({{.PluginData.GoValue}}, func() {
{{- if $Scenario.PluginData.GoHasBackground }}
_ = background(t, f)
{{- end }}
})
{{- 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 }} */
{{ end }}
{{- range .Feature.Children }}
{{ if .Background }}
{{ template "Background" .Background }}
{{- end -}}
{{ if .Scenario }}
{{ template "Scenario" .Scenario }}
{{- end -}}
{{ if .Rule }}
{{ template "Rule" .Rule }}
{{- end -}}
{{- end -}}
}