Sha256: c627954dec6eb83b740884d6ba1569067e30c3bbdecb40fdfb57a6f1ae57f4e3
Contents?: true
Size: 1.01 KB
Versions: 68
Compression:
Stored size: 1.01 KB
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("scale-generator", &j, t); err != nil { log.Fatal(err) } } // The JSON structure we expect to be able to unmarshal into type js struct { Cases []struct { Comments []string Description string Cases []struct { Description string Property string Input struct { Tonic string Intervals string } Expected []string } } } // template applied to above data structure generates the Go test cases var tmpl = `package scale {{.Header}} type scaleTest struct { description string tonic string interval string expected []string } var scaleTestCases = []scaleTest { {{range .J.Cases}} {{range .Cases}}{ description: {{printf "%q" .Description }}, tonic: {{printf "%q" .Input.Tonic }}, interval: {{printf "%q" .Input.Intervals }}, expected: {{printf "%#v" .Expected }}, }, {{end}}{{end}} } `
Version data entries
68 entries across 68 versions & 1 rubygems