vwtest

package
v0.9.14 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT, Unlicense Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultColumns = 80
	DefaultRows    = 24
)

Variables

View Source
var (
	// MkRuneKey constructs a Key instance which has given rune r and
	// given modifier mm set.  In case the control modifier is set and r
	// corresponds to one of the first 31 special keys Special is set to
	// that key otherwise Special is set to IsRune.
	MkRuneKey = backends.MkRuneKey

	// MkSpecialKey constructs a Key instance which has given special
	// key s and given modifier mm set.  In case s is one of the first
	// 31 special keys the corresponding rune and the control modifier
	// is set as well.
	MkSpecialKey = backends.MkSpecialKey
)
View Source
var PanicEventPolling = mock.PanicEventPolling

PanicEventPolling triggers a panic at the next event poll. Don't forget to actually inject an event so the conditions for the panic are met.

Functions

func Apply

func Apply(fx *Fixture, ss ...Setting) error

Apply given settings ss to given fixture fx.

func MockedBackend added in v0.9.2

func MockedBackend(ui *view.UI) *mock.UI

func SendSize

func SendSize(ui *view.UI, columns, rows uint) error

SendSize injects an initial resize event to a view.UI instance with mocked backend. Its sole purpose is to trigger content initialization by providing size information to the UI. SendSize blocks until the resize event has been processed and the UI reports the new dimensions. An optional timeout can be provided to control how long to wait.

func Settings

func Settings(fx *Fixture) *settings

Types

type ContentMock

type ContentMock struct {
	// contains filtered or unexported fields
}

ContentMock is an implementation of vw.Content interface which allows to set up a content provider for testing with less typing:

cm := new(vwtest.ContentMock).
	With(vwtest.Runes{
		vwtest.Next{ Rune: 'r', Lyt: *new(lyt.Settings).
			Add(lyt.Background(lyt.Blue)).
			Add(lyt.Foreground(lyt.Yellow))	}
	})

which of course may be shortened additionally by short aliases of used vwtest-types.

func (*ContentMock) Done

func (cm *ContentMock) Done(err error)

Err implements vw.Content.Err and stores a reported error

func (*ContentMock) DoneCount

func (cm *ContentMock) DoneCount() int

func (*ContentMock) Init

func (cm *ContentMock) Init(columns, rows int) lyt.Settings

Init implements vw.Content.Init and stores received columns and rows to make them queryable by contentMock.init.

func (*ContentMock) Next

func (cm *ContentMock) Next() (rune, lyt.Settings)

Next implements vw.view.Content.Next reporting runes along with their settings from given content mock cm's _runes filed. (see type next)

func (*ContentMock) NextCount

func (cm *ContentMock) NextCount() int

func (*ContentMock) ReceivedErr

func (cm *ContentMock) ReceivedErr() error

ReceivedErr reports an that was received through ContentMock.Err from the layout engine.

func (*ContentMock) ReceivedSize

func (cm *ContentMock) ReceivedSize() image.Point

ReceivedSize reports columns and rows counts received by an contentMock.Init call.

func (*ContentMock) With

func (cm *ContentMock) With(mock any) *ContentMock

With allows to setup the mockup. With panics on an unsupported type. Supported types are at least

  • vwtest.Runes
  • vwtest.RunesFunc

type Fixture

type Fixture struct {
	// contains filtered or unexported fields
}

Fixture implements the backends.UIer for its production vw.UI instance. It also can simulate user input.

func Register

func Register(
	t *T,
	ui *view.UI,
	fx *Fixture,
	scc *settingspkg.Contexts,
) (*Fixture, *view.UI)

Register at given settings contexts scc given view-fixture fx and given ui for given test t. Register panics if t is nil or if an fx or ui is already registered at scc. fx, ui and scc may be nil. Note returned ui has zero columns and rows whereas vwtest.View initializes an ui's size with vwview.DefaultColumns and vwview.DefaultRows.

func View

func View(t *T, ss ...settingspkg.Setting) (*Fixture, *view.UI)

View provides a view fixture whose event loop is polling for event on this fixture and which is terminated automatically on t.Cleanup.

func (*Fixture) HasQuit

func (fx *Fixture) HasQuit() bool

HasQuit reports if the quit event has been reported to given fixture fx's default quit-dummy.

func (*Fixture) IsZero

func (fx *Fixture) IsZero() bool

func (*Fixture) SendMRune

func (fx *Fixture) SendMRune(mm backends.KeyModifier, r rune)

SendMRune injects a key event with given modifiers mm and rune r into associated ui's event loop.

func (*Fixture) SendMSpecial

func (fx *Fixture) SendMSpecial(
	mm backends.KeyModifier,
	s backends.SpecialKey,
)

SendMSpecial injects a key event with given modifier mask mm and given special key s into associated ui's event loop.

func (*Fixture) SendQuit

func (fx *Fixture) SendQuit()

SendQuit sends a backend.QuitEvent to associated vw.UI's event loop.

func (*Fixture) SendRune

func (fx *Fixture) SendRune(r rune, rr ...rune)

SendRune injects a key event with given rune r into associated ui's event loop.

func (*Fixture) SendSize

func (fx *Fixture) SendSize(columns, rows uint)

SendSize issues a backend.ResizeEvent to associated vw.UI's event loop. Note SendSize does not return before given columns and rows count have been applied.

func (*Fixture) SendSpecial

func (fx *Fixture) SendSpecial(s backends.SpecialKey)

SendSpecial injects a key event with given special key s into associated ui's event loop.

type FrameEvent added in v0.9.3

type FrameEvent = backends.FrameEvent

type KeyEvent added in v0.9.3

type KeyEvent = backends.KeyEvent

type LayoutEvaluation

type LayoutEvaluation struct {
	// contains filtered or unexported fields
}

LayoutEvaluation provides a systematic api to evaluate the internal state internal/lyt.Settings of lyt.Settings. Use vwtest.Eval to crate an evaluation of the internal settings associated to a given sequence of lyt.Settings.

func Eval

func Eval(ss lyt.Settings) LayoutEvaluation

Eval maps given sequence of layout settings (function calls) to an LayoutEvaluation that allows to evaluate the corresponding internal/lyt.Settings.

func (LayoutEvaluation) BG

func (le LayoutEvaluation) BG() lyt.Color

func (LayoutEvaluation) Equals

func (le LayoutEvaluation) Equals(other LayoutEvaluation) bool

func (LayoutEvaluation) FG

func (le LayoutEvaluation) FG() lyt.Color

func (LayoutEvaluation) Goto

func (le LayoutEvaluation) Goto() (column, row int, have bool)

func (LayoutEvaluation) HasCursor

func (le LayoutEvaluation) HasCursor() bool

HasCursor returns true iff given evaluation of layout settings le has the cursor flag set.

func (LayoutEvaluation) HasGoto

func (le LayoutEvaluation) HasGoto(column, row int) bool

HasGoto reports true if given evaluation has the goto consumer flag along with given column and row set.

func (LayoutEvaluation) HasInvert

func (le LayoutEvaluation) HasInvert() bool

HasInvert return true iff given evaluation of layout settings has the invert flag set.

func (LayoutEvaluation) HasLineInversion

func (le LayoutEvaluation) HasLineInversion() bool

HasLineInversion returns true iff given evaluation of layout settings le has the invert line flag set.

type Next

type Next struct {
	Rn  rune
	Lyt lyt.Settings
}

Next represents a "next-rune" in a ContentMock having been set using vwtest.ContentMock.With(Runes{Next1 ... NextN})

type PanicEvent added in v0.9.3

type PanicEvent = backends.PanicEvent

type QuitEvent added in v0.9.3

type QuitEvent = backends.QuitEvent

type Runes

type Runes []Next

Runes may be used to setup a ContentMock using its With-method.

type RunesFunc

type RunesFunc func(columns, rows int) Runes

RunesFunc function is expected to provide a vwtest.ContentMock's runes content and is executed at initialization time when the display size has been reported to the content-mock instance. Use ContentMock.With to set a ContentMock's runes function.

type Setting

type Setting = settingspkg.Setting

func SetSize

func SetSize(columns, rows uint) Setting

func Timeout

func Timeout(d time.Duration) Setting

Jump to

Keyboard shortcuts

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