Sha256: ebc3860cae2c38a47f19b3173fc65f247efcfc7805e6c5b9806e9107f1d08b2e
Contents?: true
Size: 841 Bytes
Versions: 80
Compression:
Stored size: 841 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("word-count", &j, t); err != nil { log.Fatal(err) } } // The JSON structure we expect to be able to unmarshal into type js struct { Cases []struct { Description string Input struct { Sentence string } Expected map[string]int } } // template applied to above data structure generates the Go test cases var tmpl = `package wordcount {{.Header}} var testCases = []struct { description string input string output Frequency }{ {{range .J.Cases}}{ {{printf "%q" .Description}}, {{printf "%q" .Input.Sentence}}, Frequency{ {{range $key, $val := .Expected}} {{printf "%q: %d, " $key $val}} {{end}} }, }, {{end}}} `
Version data entries
80 entries across 80 versions & 1 rubygems