-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.tmpl
More file actions
69 lines (60 loc) · 1.83 KB
/
Copy pathfunction.tmpl
File metadata and controls
69 lines (60 loc) · 1.83 KB
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
{{define "assertion" -}}
tc.assertion(t, {{if .OnlyReturnsError}}{{template "call" .}}{{else}}err{{end}}
{{- if or (not .Subtests) .PrintInputs -}}
, fmt.Sprintf("{{template "message" .}}", {{template "inputs" .}})
{{- end -}}
)
{{- end}}
{{define "equal"}}assert.Equal{{if or (not .Subtests) .PrintInputs}}f{{end}}{{end}}
{{define "msg"}}{{if or (not .Subtests) .PrintInputs}} , "{{template "message" .}}", {{template "inputs" .}}{{end}}{{end}}
{{define "function"}}
{{- $f := .}}
func {{.TestName}}(t *testing.T) {
for {{if (or .Subtests (not .IsNaked))}} _, tc := {{end}} range []struct {
name string
{{- range .TestParameters}}
{{- if eq "name" (Param .)}}// FIXME: name collision! {{- end}}
{{Param .}} {{.Type}}
{{- end}}
{{- with .Receiver}}
{{Receiver .}} {{.Type}}
{{- end}}
{{- range .TestResults}}
{{Want .}} {{.Type}}
{{- end}}
{{- if .ReturnsError}}
assertion assert.ErrorAssertionFunc
{{- end}}
} {
// TODO: Add test cases.
} {
{{- if .Subtests}}
{{- if .Parallel}}tc := tc{{end}}
t.Run(tc.name, func(t *testing.T) {
{{- if .Parallel}}t.Parallel(){{end}}
{{- end}}
{{- with .Receiver}}
{{- if .IsStruct}}
{{Receiver .}} := tc.{{Receiver .}}
{{- end}}
{{- end}}
{{- range .Parameters}}
{{- if .IsWriter}}
{{Param .}} := &bytes.Buffer{}
{{- end}}
{{- end}}
{{template "results" $f}} {{template "call" $f}}
{{- if .ReturnsError}}
{{template "assertion" $f}}
{{- end}}
{{- range .TestResults}}
{{- if .IsWriter}}
{{template "equal" $f}}(t, tc.{{Want .}}, {{Param .}}.String(){{template "msg" $f}})
{{- else}}
{{template "equal" $f}}(t, tc.{{Want .}}, {{Got .}}{{template "msg" $f}})
{{- end}}
{{- end}}
{{- if .Subtests }} }) {{- end -}}
}
}
{{end}}