Sha256: 6e89d83acfad721fc366fdee7713dbedfa44fe1de76d7d32a8a8b7d90adac044
Contents?: true
Size: 853 Bytes
Versions: 32
Compression:
Stored size: 853 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("hamming", &j, t); err != nil { log.Fatal(err) } } // The JSON structure we expect to be able to unmarshal into type js struct { Cases []oneCase } type oneCase struct { Description string Strand1 string Strand2 string Expected interface{} } func (o oneCase) Want() int { d, ok := o.Expected.(float64) if ok { return int(d) } return -1 } // template applied to above data structure generates the Go test cases var tmpl = `package hamming {{.Header}} var testCases = []struct { s1 string s2 string want int }{ {{range .J.Cases}}{ // {{.Description}} {{printf "%q" .Strand1}}, {{printf "%q" .Strand2}}, {{.Want}}, }, {{end}}} `
Version data entries
32 entries across 32 versions & 1 rubygems