Sha256: d869e64fcef0e02e1d861d94d297df00f03237e16aa1be246a88bf1ae2e10aa1

Contents?: true

Size: 1.09 KB

Versions: 72

Compression:

Stored size: 1.09 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       struct {
		Instructions []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.Instructions}},
{{printf "%#v" .Expected}},
},
{{end}}
},
},
{{end}}
}
`

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.179 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.178 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.177 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.176 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.175 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.174 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.173 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.172 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.171 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.170 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.169 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.167 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.166 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.165 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.164 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.163 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.162 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.161 tracks/go/exercises/forth/.meta/gen.go
trackler-2.2.1.160 tracks/go/exercises/forth/.meta/gen.go