Help us shape the future of Go! Take the 2026 Go Developer Survey

propgen

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package propgen makes prop values for a component from its prop type and writes a prop value as Go source. `gx fuzz` renders the values (REQ-AI-11); the capture of the dev client writes a value into a fixtures file (REQ-AI-12). The package runs in a dev build of an app only.

Index

Constants

This section is empty.

Variables

View Source
var (
	LongString   = strings.TrimSpace(strings.Repeat("Lorem ipsum dolor sit amet ", 80))
	MarkupString = `<b>"x" & 'y'</b><script>alert(1)</script></div>`
)

LongString and MarkupString are the two fixed string values.

Functions

func CanMake

func CanMake(t reflect.Type) bool

CanMake reports whether Set can give a value other than the zero value to a prop of the type t. It cannot for an interface other than gx.Node, a function, a channel, a value that the app vouches for, and a struct with no exported field. `gx fuzz` does not render a component with a required prop of such a type: the zero value is not an input that a caller gives.

func ClearNodes

func ClearNodes(v reflect.Value) bool

ClearNodes sets each gx.Node of the prop value v to nil, and reports whether one had a value. v is addressable. `gx fuzz` renders the result to see whether a defect of the tree comes from the content of a slot or from the component.

func Fixture

func Fixture(v reflect.Value, pkgPath string, h Hooks) (src string, imports []string, err error)

Fixture writes the prop value v as the value of one entry of a gx.Fixtures literal: a composite literal with no type, for example `{Title: "Card", Count: 3}`. pkgPath is the package of the fixtures file. imports holds the import of each package that the source names: the import path, or `name "path"` when two packages of the source have one name.

A gx.Node becomes a gx.Raw call with the HTML that the node renders. The error names the prop that Go source cannot hold: a function, a channel or a field of a different package that is not exported.

func Seed

func Seed(seed uint64, pkgPath, component string, index int) (uint64, uint64)

Seed returns the two seed words of the generator of one prop set. The sets of one component do not change when a different component joins the run.

func Set

func Set(t reflect.Type, rng *rand.Rand, mode Mode, h Hooks) reflect.Value

Set returns a value of the prop type t.

Types

type Case

type Case struct {
	Index int `json:"index"`
	// Fixture is the prop set as an entry value of a gx.Fixtures literal.
	// It is empty when Go source cannot hold the set; Unprintable then
	// says why.
	Fixture     string   `json:"fixture"`
	Imports     []string `json:"imports,omitempty"`
	Unprintable string   `json:"unprintable,omitempty"`
	// Panic is the panic value of the render, or empty.
	Panic string `json:"panic,omitempty"`
	// HTML is what the render wrote.
	HTML string `json:"html"`
	// Slots is true when a gx.Node of the set has a value. Bare is then
	// what the render wrote with each gx.Node set to nil.
	Slots bool   `json:"slots,omitempty"`
	Bare  string `json:"bare,omitempty"`
}

Case is one prop set of a component.

type Component

type Component struct {
	Name, Package string
	// contains filtered or unexported fields
}

Component is one component function of an app. Package gx has no reflection (checks/no-reflection.sh), so the calls are here.

func Find

func Find(values map[string]reflect.Value, pkgPath, name string) (c Component, ok bool)

Find returns the component with the given name from the package-level values of its package. ok is false when the values hold no function from one props struct to a gx.Node under that name.

func (Component) Call

func (c Component) Call(p Props) any

Call calls the component with the props and returns its gx.Node, inside the <Name>Wrap function when the fixtures file has one. A panic of the component goes to the caller.

func (Component) CannotMake

func (c Component) CannotMake() []string

CannotMake names the props whose type has only the zero value in a prop set.

func (Component) Of

func (c Component) Of(v any) (Props, bool)

Of returns the prop value v of the component, when v has the type of its props.

func (Component) Set

func (c Component) Set(seed uint64, index int, h Hooks) Props

Set returns the prop set of the component with the given index.

type Hooks

type Hooks struct {
	// Text returns gx.Text(s).
	Text func(s string) any
	// HTML returns the HTML that a gx.Node renders.
	HTML func(node any) (string, error)
}

Hooks are the two operations on a gx.Node that the package needs.

type Mode

type Mode int

Mode selects the strings of one prop set.

const (
	// Zero is the zero value of each prop: each string is empty.
	Zero Mode = iota
	// Long gives each string a long value.
	Long
	// Markup gives each string a value with markup characters.
	Markup
	// Mixed selects one of the kinds for each string at random.
	Mixed
)

func ModeOf

func ModeOf(index int) Mode

ModeOf returns the mode of the prop set with the given index. The first three sets hold the empty value, a long string and markup characters in each string; each later set is mixed.

type Props

type Props struct {
	// contains filtered or unexported fields
}

Props is one prop value of a component.

func (Props) ClearNodes

func (p Props) ClearNodes() bool

ClearNodes sets each gx.Node of the props to nil.

func (Props) Fixture

func (p Props) Fixture(pkgPath string, h Hooks) (src string, imports []string, err error)

Fixture writes the props as an entry value of a gx.Fixtures literal.

type Report

type Report struct {
	Seed    uint64   `json:"seed"`
	Targets []Target `json:"targets"`
}

Report is the answer of the dev route /_gx/fuzz: the prop sets of each component of the app, and what the render of each set gave.

type Target

type Target struct {
	Component string `json:"component"`
	// Package is the import path of the component.
	Package string `json:"package"`
	// Skipped says why the component has no sets: the symbol table of
	// the app does not hold its function.
	Skipped string `json:"skipped,omitempty"`
	// CannotMake names the props whose type has only the zero value in a
	// prop set: an interface, a function, a channel.
	CannotMake []string `json:"cannotMake,omitempty"`
	Cases      []Case   `json:"cases"`
}

Target is one component.

Jump to

Keyboard shortcuts

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