flatest

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 8 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 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 (*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]) 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]) Frame

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

Frame renders the current state without changing it.

func (*Driver[S]) Quit

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

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

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.

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 are skipped: the fresh Driver delivers its own initial resize at the fixed width.

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