flatest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package flatest is a deterministic, synchronous test harness for flat apps: it drives an App through scripted events and controlled time, exercising real async folds without goroutine races, real clocks, or a terminal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertFrames

func AssertFrames(t *testing.T, path string, frames []flatte.Frame)

AssertFrames compares a frame sequence against a golden: each frame RenderFrame'd, joined by a separator line, so an interaction can be regression-tested as an ordered series of frames.

func AssertGolden

func AssertGolden(t *testing.T, path string, frame string)

func AssertGoldenFrame

func AssertGoldenFrame(t *testing.T, path string, frame flatte.Frame)

AssertGoldenFrame compares a Frame against a golden: cleaned content, then metadata footer lines — only when metadata is set, so frames without cursor or title keep their existing goldens byte-identical.

func CleanFrame

func CleanFrame(frame string) string

func Frames

func Frames[S any](d *Driver[S], steps ...func(*Driver[S])) []flatte.Frame

Frames runs the driver through a sequence of steps and returns the frame after each, for sequence goldens (see AssertFrames).

func NewHarnessEffects added in v0.2.0

func NewHarnessEffects[S any](ctx context.Context, updates chan<- flatte.StateUpdate[S], quit func(), dispatch func(func()), clock flatte.Clock) flatte.Effects[S]

NewHarnessEffects builds an Effects value for callback-level tests that need to pass Effects directly to Handle or observe named updates. Prefer Start when a test should exercise the complete app loop.

func NewHarnessEffectsQueue added in v0.2.0

func NewHarnessEffectsQueue[S any](ctx context.Context, enqueue func(flatte.StateUpdate[S]) bool, quit func(), dispatch func(func()), clock flatte.Clock) flatte.Effects[S]

NewHarnessEffectsQueue is NewHarnessEffects with a caller-owned update queue, useful when tests must avoid blocking on channel capacity.

func RenderFrame

func RenderFrame(frame flatte.Frame) string

RenderFrame serializes a frame for golden comparison.

Types

type Driver

type Driver[S any] struct {
	// contains filtered or unexported fields
}

Driver runs a flatte.App synchronously for tests. App-triggered async (Go/Latest/Stream) is deferred to a pending queue and only runs on Settle; time-based effects (Every) are driven by a fake clock advanced with Advance. The width is fixed so frames are deterministic.

func Start

func Start[S any](app flatte.App[S], width int) *Driver[S]

Start builds a Driver, runs Init, delivers the initial ResizeEvent, and renders the first frame.

func StartWith added in v0.2.0

func StartWith[S any](app flatte.App[S], opts Options) *Driver[S]

StartWith builds a Driver with an explicit size and host render context.

func (*Driver[S]) Advance

func (d *Driver[S]) Advance(by time.Duration) flatte.Frame

Advance moves the fake clock, firing due Every ticks (which queue updates), then settles any async those ticks triggered.

func (*Driver[S]) Answer added in v0.2.0

func (d *Driver[S]) Answer(r flatte.DialogResult) flatte.Frame

Answer answers the oldest open dialog as the user would — the chosen paths (none: cancelled) or button (-1: dismissed) — applies the app's fold, and returns the rendered frame. It panics when no dialog is open.

func (*Driver[S]) Close

func (d *Driver[S]) Close()

Close calls the app's OnExit hook, mirroring what Run does on loop exit. Call it at the end of a test to verify state-save callbacks.

func (*Driver[S]) Dialog added in v0.2.0

func (d *Driver[S]) Dialog() (dialog flatte.Dialog, ok bool)

Dialog is the oldest dialog the app asked for (OpenFile, SaveFile, Alert) that the test has not answered; ok is false when there is none. The driver draws no dialogs: tests answer them with Answer.

func (*Driver[S]) Frame

func (d *Driver[S]) Frame() flatte.Frame

Frame renders the current state through the same settled cell-frame rules as Send, Resize, and Run.

func (*Driver[S]) Notifications added in v0.2.0

func (d *Driver[S]) Notifications() []flatte.Notification

Notifications are the notifications the app posted with Notify, oldest first. The driver shows none; tests read them here.

func (*Driver[S]) Quit

func (d *Driver[S]) Quit() bool

Quit reports whether the app has requested quit via fx.Quit().

func (*Driver[S]) Resize added in v0.2.0

func (d *Driver[S]) Resize(width, height int) flatte.Frame

Resize updates dimensions used by Handle, View, and root layout composition.

func (*Driver[S]) Send

func (d *Driver[S]) Send(ev flatte.Event) flatte.Frame

Send delivers one event, drains the synchronous updates it produced, and returns the rendered frame. Async results triggered by the event are NOT applied here — call Settle.

func (*Driver[S]) Settle

func (d *Driver[S]) Settle() flatte.Frame

Settle runs every pending async body (to fixpoint — a body may dispatch more) and drains the updates each produces, then renders. This is where Go/Latest/Stream results land, under test control. drain runs after each body so Latest's apply-time guard sees a superseded ctx and drops the stale result.

func (*Driver[S]) State

func (d *Driver[S]) State() *S

State exposes the live state for field assertions.

func (*Driver[S]) WindowFrame added in v0.2.0

func (d *Driver[S]) WindowFrame(id string) (frame flatte.Frame, ok bool)

WindowFrame is secondary window id's own frame as last rendered (composed at its size, without the box the terminal draws around it); ok is false when the app does not declare it. Mouse events for it are sent in screen cells, as a terminal reports them: over its box in Frame.

type Options added in v0.2.0

type Options struct {
	Width, Height int
	Graphical     bool
	Capabilities  flatte.Capabilities
	// Theme is the app's design system, as flatte.WithTheme sets it (nil:
	// none; a Graphical driver then reports theme.Default()). A terminal
	// driver composes its cells in the theme's dark palette, as a terminal
	// run does, until Close.
	Theme *theme.Theme
}

Options configures the deterministic render context of a Driver.

type Recorder

type Recorder struct {
	Steps []Step
}

Recorder is a flatte.Tracer that captures the ordered event/update stream of a session for replay assertions. Use it as App.Tracer.

func Replay

func Replay[S any](app flatte.App[S], width int, rec *Recorder) *Recorder

Replay re-drives the recorded EVENTS through a fresh Driver — settling after each so any async those events trigger lands — and returns the new recording. A test asserts the two update-name streams match: a regression lock on event→update determinism.

Limitations (honest): updates are closures and are not serialized, so only their names are compared. Settle/Advance cadence is NOT captured, so a session that batches several events before settling (e.g. a Latest supersede) will not reproduce identically under per-event settling — drive those with the Driver directly. ResizeEvents and LayoutEvents are skipped: the fresh Driver delivers its own initial resize at the fixed width and settles its own layout, exactly as the recorded session did.

func (*Recorder) Event

func (r *Recorder) Event(ev flatte.Event)

func (*Recorder) Events

func (r *Recorder) Events() []flatte.Event

Events returns the recorded events in order.

func (*Recorder) Update

func (r *Recorder) Update(name string)

func (*Recorder) Updates

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

Updates returns the recorded update names in order.

type Step

type Step struct {
	Event  flatte.Event // non-nil for an event step
	Update string       // non-empty for an update step
}

Step is one entry in a recorded session: either an event the loop received or an update that was applied.

Jump to

Keyboard shortcuts

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