Sha256: 5d925aed37b2e3441a773cbf5b78916b4d6dd756b49ea9fc3eeefccff92a5642

Contents?: true

Size: 1.71 KB

Versions: 38

Compression:

Stored size: 1.71 KB

Contents

package main

import (
	"encoding/json"
	"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("run-length-encoding", &j, t); err != nil {
		log.Fatal(err)
	}
}

// The JSON structure we expect to be able to umarshal into
type js struct {
	Groups []testGroup `json:"Cases"`
}

type testGroup struct {
	Description string
	Cases       []json.RawMessage `property:"RAW"`
	EncodeCases []struct {
		Description string
		Input       string
		Expected    string
	} `property:"encode"`
	DecodeCases []struct {
		Description string
		Input       string
		Expected    string
	} `property:"decode"`
	EncodeDecodeCases []struct {
		Description string
		Input       string
		Expected    string
	} `property:"consistency"`
}

var tmpl = `package encode

{{.Header}}

{{range .J.Groups}}
	// {{ .Description }}

	{{- if .EncodeCases }}
		var encodeTests = []struct {
			input string
			expected string
			description string
		}{
			{{- range .EncodeCases }}
				{ {{.Input | printf "%q"}}, {{.Expected | printf "%q"}}, {{.Description | printf "%q"}} },
			{{- end }}
		}
	{{- end }}

	{{- if .DecodeCases }}
		var decodeTests = []struct {
			input string
			expected string
			description string
		}{
			{{- range .DecodeCases }}
				{ {{.Input | printf "%q"}}, {{.Expected | printf "%q"}}, {{.Description | printf "%q"}} },
			{{- end }}
		}
	{{- end }}

	{{- if .EncodeDecodeCases }}
		var encodeDecodeTests = []struct {
			input string
			expected string
			description string
		}{
			{{- range .EncodeDecodeCases }}
				{ {{.Input | printf "%q"}}, {{.Expected | printf "%q"}}, {{.Description | printf "%q"}} },
			{{- end }}
		}
	{{- end }}
{{end}}
`

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
trackler-2.2.1.81 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.80 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.79 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.78 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.77 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.76 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.75 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.74 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.73 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.72 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.71 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.70 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.69 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.68 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.67 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.66 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.65 tracks/go/exercises/run-length-encoding/.meta/gen.go
trackler-2.2.1.64 tracks/go/exercises/run-length-encoding/.meta/gen.go