irtest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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
}

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 New

func New() *Recorder

New returns an empty Recorder.

func (*Recorder) Count

func (r *Recorder) Count(op string) int

Count returns how many calls of the given op were recorded.

func (*Recorder) FillPath

func (r *Recorder) FillPath(p *ir.Path, fill ir.Fill, rule ir.FillRule)

func (*Recorder) Filter

func (r *Recorder) Filter(op string) []Call

Filter returns the recorded calls of the given op.

func (*Recorder) Flush

func (r *Recorder) Flush() error

func (*Recorder) Image

func (r *Recorder) Image(img image.Image, dst ir.Rect)

func (*Recorder) Markers

func (r *Recorder) Markers(shape ir.Marker, at []ir.Point, style ir.MarkerStyle)

func (*Recorder) Measure

func (r *Recorder) Measure(run ir.TextRun) ir.TextMetrics

func (*Recorder) Ops

func (r *Recorder) Ops() []string

Ops returns the recorded operation names, for a quick order assertion.

func (*Recorder) Polyline

func (r *Recorder) Polyline(pts []ir.Point, style ir.Stroke)

func (*Recorder) Pop

func (r *Recorder) Pop()

func (*Recorder) Push

func (r *Recorder) Push(clip *ir.Path, xform ir.Affine)

func (*Recorder) String

func (r *Recorder) String() string

String renders the recording as a short, diffable trace.

func (*Recorder) StrokePath

func (r *Recorder) StrokePath(p *ir.Path, style ir.Stroke)

func (*Recorder) Text

func (r *Recorder) Text(run ir.TextRun)

func (*Recorder) Texts

func (r *Recorder) Texts() []string

Texts returns the strings of every recorded text run, in order.

Jump to

Keyboard shortcuts

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