Sha256: f03dba1e2af71fbea9c5b2d25941b239d73c4a179f5539055545186978ad4fba
Contents?: true
Size: 831 Bytes
Versions: 30
Compression:
Stored size: 831 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 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}}, {{printf "%#v" .Expected}}, }, {{end}}{{end}}} `
Version data entries
30 entries across 30 versions & 1 rubygems