Sha256: 325ebed6062e28fbad1719c28ee443030689f095f08aea2cfc3bd0d5ee4271aa
Contents?: true
Size: 854 Bytes
Versions: 77
Compression:
Stored size: 854 Bytes
Contents
package main import ( "log" "text/template" "../../../gen" ) func main() { t, err := template.New("").Parse(tmpl) if err != nil { log.Fatal(err) } var j js if err := gen.Gen("prime-factors", &j, t); err != nil { log.Fatal(err) } } // The JSON structure we expect to be able to unmarshal into type js struct { Groups []TestGroup `json:"cases"` } type TestGroup struct { Description string Cases []OneCase } type OneCase struct { Description string Input struct { Value int64 } Expected []int64 } // template applied to above data structure generates the Go test cases var tmpl = `package prime {{.Header}} var tests = []struct { description string input int64 expected []int64 }{ {{range .J.Groups}} {{range .Cases}} { "{{.Description}}", {{.Input.Value}}, {{printf "%#v" .Expected}}, }, {{end}}{{end}}} `
Version data entries
77 entries across 77 versions & 1 rubygems