forked from exercism/go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen.go
More file actions
48 lines (42 loc) · 871 Bytes
/
gen.go
File metadata and controls
48 lines (42 loc) · 871 Bytes
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
package main
import (
"log"
"text/template"
"../../../../gen"
)
func main() {
t, err := template.New("").Parse(tmpl)
if err != nil {
log.Fatal(err)
}
var j = map[string]interface{}{
"eggCount": &[]testCase{},
}
if err := gen.Gen("eliuds-eggs", j, t); err != nil {
log.Fatal(err)
}
}
type testCase struct {
Description string `json:"description"`
Input struct {
Number int `json:"number"`
} `json:"input"`
Expected int `json:"expected"`
}
// Template to generate various test cases.
var tmpl = `package eliudseggs
{{.Header}}
type testCase struct {
description string
input int
expected int
}
var testCases = []testCase{
{{range .J.eggCount}}{
description: {{printf "%q" .Description}},
input: {{printf "%d" .Input.Number}},
expected: {{printf "%d" .Expected}},
},
{{end}}
}
`