-
Notifications
You must be signed in to change notification settings - Fork 3
/
std.simple.v1.go.tmpl
135 lines (104 loc) · 3.41 KB
/
std.simple.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
134
135
package {{ .PackageName }}
import (
"testing"
)
{{ define "Background" }}
{{- $Background := . -}}
background := func(t *testing.T) interface{} {
{{- range $Background.Steps }}
// {{ .Keyword }}{{ .Text | trimSpace | withFinalDot }}
{{ end }}
return nil // TODO: Feel free to modify return value(s).
}
{{ end }}
{{ define "Scenario" }}
{{- $Scenario := . -}}
t.Run({{ $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) {
{{- 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 }}
}
for name, tc := range testCases {
{{- if $Scenario.PluginData.GoParallel }}
tc := tc
{{ end -}}
t.Run(name, func(t *testing.T) {
{{- if $Scenario.PluginData.GoParallel }}
t.Parallel()
{{ end -}}
_ = tc // TODO: Use and remove.
{{- if $Scenario.PluginData.GoHasBackground }}
_ = background(t)
{{ end -}}
{{- range $Scenario.Steps }}
// {{ .Keyword }}{{ .Text | trimSpace | withFinalDot }}
{{ end }}
})
}
{{- else }}
{{- if $Scenario.PluginData.GoParallel }}
t.Parallel()
{{ end -}}
{{- if $Scenario.PluginData.GoHasBackground }}
_ = background(t)
{{ end }}
{{- range $Scenario.Steps }}
// {{ .Keyword }}{{ .Text | trimSpace | withFinalDot }}
{{ end -}}
{{ end }}
})
{{ end }}
{{ define "Rule" }}
{{ $Rule := . }}
t.Run({{ $Rule.PluginData.GoValue }}, func({{- if $Rule.PluginData.GoParallel -}}t{{- else -}}_{{- end -}} *testing.T) {
{{- 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 -}}
{{ 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 -}}
}