Sha256: a4f5520677318bbbb66cc352acd92131f13667243ea5bf539f84225cb12a1818

Contents?: true

Size: 1.05 KB

Versions: 150

Compression:

Stored size: 1.05 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("forth", &j, t); err != nil {
		log.Fatal(err)
	}
}

// The JSON structure we expect to be able to unmarshal into
type js struct {
	Groups []Group `json:"cases"`
}

// A group of test cases.
type Group struct {
	Name  string `json:"description"`
	Cases []OneCase
}

// One test case.
type OneCase struct {
	Description string
	Input       []string
	Expected    []int
}

// template applied to above data structure generates the Go test cases
var tmpl = `package forth

{{.Header}}

type testGroup struct {
	group	string
	tests	[]testCase
}

type testCase struct {
	description	string
	input		[]string
	expected	[]int // nil slice indicates error expected.
}

var testGroups = []testGroup{
{{range .J.Groups}}{
group: {{printf "%q"  .Name}},
tests: []testCase{
{{range .Cases}}{
{{printf "%q"  .Description}},
{{printf "%#v" .Input}},
{{printf "%#v" .Expected}},
},
{{end}}
},
},
{{end}}
}
`

Version data entries

150 entries across 150 versions & 1 rubygems

Version Path
trackler-2.2.1.106 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.105 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.104 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.103 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.102 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.101 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.100 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.99 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.98 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.97 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.96 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.95 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.94 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.93 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.92 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.91 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.90 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.89 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.88 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.87 tracks/go/exercises/forth/.meta/gen.go