Documentation
¶
Overview ¶
Package irtest provides a recording ir.Backend for tests.
It lets a test assert on what a geom or the renderer actually emitted — which primitives, in which order, with which style — instead of inspecting rendered pixels or scraped SVG. That keeps model-layer tests independent of any backend.
Index ¶
- func NullBackend() ir.Backend
- func NullTarget() ir.Target
- type Call
- type Recorder
- func (r *Recorder) Count(op string) int
- func (r *Recorder) Damage(rects []ir.Rect)
- func (r *Recorder) FillPath(p *ir.Path, fill ir.Fill, rule ir.FillRule)
- func (r *Recorder) Filter(op string) []Call
- func (r *Recorder) Flush() error
- func (r *Recorder) Image(img image.Image, dst ir.Rect)
- func (r *Recorder) Markers(shape ir.Marker, at []ir.Point, style ir.MarkerStyle)
- func (r *Recorder) Measure(run ir.TextRun) ir.TextMetrics
- func (r *Recorder) Ops() []string
- func (r *Recorder) Polyline(pts []ir.Point, style ir.Stroke)
- func (r *Recorder) Pop()
- func (r *Recorder) Push(clip *ir.Path, xform ir.Affine)
- func (r *Recorder) Reset()
- func (r *Recorder) String() string
- func (r *Recorder) StrokePath(p *ir.Path, style ir.Stroke)
- func (r *Recorder) Target() ir.Target
- func (r *Recorder) Text(run ir.TextRun)
- func (r *Recorder) Texts() []string
- func (r *Recorder) Trace() []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NullBackend ¶ added in v0.4.0
NullBackend returns an ir.Backend that draws nothing and remembers nothing, measuring with the same built-in table Recorder uses.
It is what a benchmark renders into when the thing being measured is refract's own work: with a real emitter most of a frame's time and memory belongs to the emitter, and a gate on refract's allocations would be reading someone else's.
func NullTarget ¶ added in v0.4.0
NullTarget returns an ir.Target handing out NullBackend.
Types ¶
type Call ¶
type Call struct {
Op string
Points []ir.Point
Path *ir.Path
Stroke ir.Stroke
Fill ir.Fill
Rule ir.FillRule
Text ir.TextRun
Marker ir.Marker
Style ir.MarkerStyle
Image image.Image
Rect ir.Rect
Affine ir.Affine
HasClip bool
ClipRect ir.Rect
}
Call is one recorded drawing operation.
type Recorder ¶
type Recorder struct {
Calls []Call
Depth int
// MaxDepth is the deepest the Push/Pop stack ever got, which is how a test
// checks that clipping was actually applied around the data layers.
MaxDepth int
// Damaged is what each frame was told to repaint, one entry per call to
// [Recorder.Damage], and Whole says which of those meant the whole frame.
// Frames counts the frames flushed.
Damaged [][]ir.Rect
Whole []bool
Frames int
}
Recorder is an ir.Backend that remembers every call.
It measures with the same built-in metrics table the SVG backend falls back to, so layout in a test behaves like layout in a real stdlib-only render.
func (*Recorder) Damage ¶ added in v0.5.0
Damage implements ir.Partial: it records what a frame was told to repaint rather than repainting anything.
It is how a test checks damage tracking end to end — that a chart whose data moved repaints where it moved and not the whole canvas.
func (*Recorder) Reset ¶ added in v0.5.0
func (r *Recorder) Reset()
Reset clears the recording, keeping the memory. A test driving several frames through one Recorder calls it between them.
func (*Recorder) Target ¶ added in v0.5.0
Target returns an ir.Target handing out r, so that a test can drive github.com/timzifer/refract.Plot.Render or Plot.Live through a recorder. Closing it does nothing: a recorder has nothing to finalise.
func (*Recorder) Trace ¶ added in v0.5.0
Trace renders the recording one line per call, with the geometry and the style spelled out.
It is Recorder.String at the detail a comparison needs: two charts that produce the same trace are the same chart, which is how a spec round trip is checked without a golden file. Coordinates are printed to three decimals, the same precision the SVG emitter writes.