-
-
Notifications
You must be signed in to change notification settings - Fork 658
/
Copy pathgen.go
50 lines (42 loc) · 902 Bytes
/
gen.go
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
package main
import (
"log"
"text/template"
"../../../../gen"
)
func main() {
t, err := template.New("").Parse(tmpl)
if err != nil {
log.Fatal(err)
}
j := map[string]interface{}{
"roman": &[]testCase{},
}
if err := gen.Gen("roman-numerals", j, t); err != nil {
log.Fatal(err)
}
}
type testCase struct {
Description string `json:"description"`
Input struct {
Number int `json:"number"`
} `json:"input"`
Expected string `json:"expected"`
}
// template applied to above data structure generates the Go test cases
var tmpl = `package romannumerals
{{.Header}}
type romanNumeralTest struct {
description string
input int
expected string
}
var validRomanNumeralTests = []romanNumeralTest{
{{range .J.roman}}{
description: {{printf "%q" .Description}},
input: {{printf "%d" .Input.Number}},
expected: {{printf "%q" .Expected}},
},
{{end}}
}
`