Sha256: 73b22be0d9beafca185d38e75980b6222087a7801ff21bd2e2ab1a0b4d90dcc3
Contents?: true
Size: 1.8 KB
Versions: 110
Compression:
Stored size: 1.8 KB
Contents
package main import ( "encoding/json" "log" "strings" "text/template" "../../../gen" ) func main() { t, err := template.New("").Parse(tmpl) if err != nil { log.Fatal(err) } var j js if err := gen.Gen("clock", &j, t); err != nil { log.Fatal(err) } } // The JSON structure we expect to be able to umarshal into type js struct { Groups []testGroup `json:"Cases"` } type testGroup struct { Description string Cases []json.RawMessage `property:"RAW"` CreateCases []struct { Description string Hour, Minute int Expected string } `property:"create"` AddCases []struct { Description string Hour, Minute, Add int Expected string } `property:"add"` EqCases []struct { Description string Clock1, Clock2 struct{ Hour, Minute int } Expected bool } `property:"equal"` } func (groups testGroup) GroupShortName() string { return strings.ToLower(strings.Fields(groups.Description)[0]) } var tmpl = `package clock {{.Header}} {{range .J.Groups}} // {{ .Description }} {{- if .CreateCases }} var timeTests = []struct { h, m int want string }{ {{- range .CreateCases }} { {{.Hour}}, {{.Minute}}, {{.Expected | printf "%#v"}}}, // {{.Description}} {{- end }} } {{- end }} {{- if .AddCases }} var {{ .GroupShortName }}Tests = []struct { h, m, a int want string }{ {{- range .AddCases }} { {{.Hour}}, {{.Minute}}, {{.Add}}, {{.Expected | printf "%#v"}}}, // {{.Description}} {{- end }} } {{- end }} {{- if .EqCases }} type hm struct{ h, m int } var eqTests = []struct { c1, c2 hm want bool }{ {{- range .EqCases }} // {{.Description}} { hm{ {{.Clock1.Hour}}, {{.Clock1.Minute}}}, hm{ {{.Clock2.Hour}}, {{.Clock2.Minute}}}, {{.Expected}}, }, {{- end }} } {{- end }} {{end}} `
Version data entries
110 entries across 110 versions & 1 rubygems