Sha256: b22940f5296b82581a71743be83e69efb0b4056f2bc6b14e21577b5e0eb971d9

Contents?: true

Size: 1.64 KB

Versions: 76

Compression:

Stored size: 1.64 KB

Contents

// +build ignore

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

// The JSON structure we expect to be able to umarshal into
type js struct {
	Create struct {
		Description []string
		Cases       []timeCase
	}
	Add struct {
		Description []string
		Cases       []addCase
	}
	Equal struct {
		Description []string
		Cases       []eqCase
	}
}

// Handle the three tests similarly

type timeCase struct {
	Description  string
	Hour, Minute int
	Expected     string
}
type addCase struct {
	Description       string
	Hour, Minute, Add int
	Expected          string
}
type eqCase struct {
	Description    string
	Clock1, Clock2 struct{ Hour, Minute int }
	Expected       bool
}

var tmpl = `package clock

// Source: {{.Ori}}
{{if .Commit}}// Commit: {{.Commit}}
{{end}}

{{range .J.Create.Description}}// {{.}}
{{end}}var timeTests = []struct {
	h, m int
	want string
}{
{{range .J.Create.Cases}}{ {{.Hour}}, {{.Minute}}, {{.Expected | printf "%#v"}}},	// {{.Description}}
{{end}}}

{{range .J.Add.Description}}// {{.}}
{{end}}var addTests = []struct {
	h, m, a int
	want  string
}{
{{range .J.Add.Cases}}{ {{.Hour}}, {{.Minute}}, {{.Add}}, {{.Expected | printf "%#v"}}}, // {{.Description}}
{{end}}}

{{range .J.Equal.Description}}// {{.}}
{{end}}type hm struct{ h, m int }

var eqTests = []struct {
	c1, c2 hm
	want   bool
}{
{{range .J.Equal.Cases}}// {{.Description}}
{
	hm{ {{.Clock1.Hour}}, {{.Clock1.Minute}}},
	hm{ {{.Clock2.Hour}}, {{.Clock2.Minute}}},
	{{.Expected}},
},
{{end}}}`

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
trackler-2.0.8.2 tracks/go/exercises/clock/example_gen.go
trackler-2.0.8.1 tracks/go/exercises/clock/example_gen.go
trackler-2.0.7.0 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.44 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.43 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.42 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.41 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.40 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.39 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.38 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.37 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.36 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.35 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.34 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.33 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.32 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.31 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.30 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.29 tracks/go/exercises/clock/example_gen.go
trackler-2.0.6.28 tracks/go/exercises/clock/example_gen.go