gen

package
v0.0.0-...-2a5f78d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

package gen contains the commmon code used by practice exercises to generate `cases_test.go` from canonical data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorMessage

func ErrorMessage(v any) string

ErrorMessage extracts the error string from a canonical-data.json error object. Error objects have the form {"error": "some message"}. Returns "" if v is not an error object or contains no error string.

func FloatSliceToInts

func FloatSliceToInts(v any) []int

FloatSliceToInts converts a JSON-decoded []any of float64 values to []int. Returns nil if v is not a []any or if any element is not a float64.

func Gen

func Gen(exercise string, tests map[string]interface{}, t *template.Template) error

Gen generates the exercise cases_test.go file from the relevant canonical-data.json

func IsError

func IsError(v any) bool

IsError reports whether v is a canonical-data.json error object (i.e., {"error": "..."}).

func PackageName

func PackageName(exerciseSlug string) string

PackageName gives the Go package name from an exercise slug.

Types

type Commit

type Commit struct {
	Sha     string
	Details struct {
		Message string
	} `json:"commit"`
}

func (Commit) Summary

func (c Commit) Summary() string
type Header struct {
	Commit string
	Origin string
	Slug   string
}

Header tells how the test data was generated, for display in the header of cases_test.go

func (Header) String

func (h Header) String() string

String generates the header for cases_test.go file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL