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 ¶
- Variables
- func CanMake(t reflect.Type) bool
- func ClearNodes(v reflect.Value) bool
- func Fixture(v reflect.Value, pkgPath string, h Hooks) (src string, imports []string, err error)
- func Seed(seed uint64, pkgPath, component string, index int) (uint64, uint64)
- func Set(t reflect.Type, rng *rand.Rand, mode Mode, h Hooks) reflect.Value
- type Case
- type Component
- type Hooks
- type Mode
- type Props
- type Report
- type Target
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
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 ¶
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 ¶
CannotMake names the props whose type has only the zero value in a prop set.
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 Props ¶
type Props struct {
// contains filtered or unexported fields
}
Props is one prop value of a component.
func (Props) ClearNodes ¶
ClearNodes sets each gx.Node of the props to nil.
type Report ¶
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.