mock

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ColumnsDefault is reported by UI.Size if an ui's set columns
	// dimension is zero.
	ColumnsDefault = 80

	// RowsDefault is reported by UI.Size if an ui's set rows dimension
	// is zero.
	RowsDefault = 24
)

Variables

View Source
var DefaultExecuteDone = true

DefaultExecuteDone is reported by Repainter instance which is out of Repainter.ContinueExecution values.

View Source
var DefaultNextRepaintDuration = time.Duration(0)

DefaultNextRepaintDuration is reported by an Repainter instance which is out of Repainter.WantNextRepaintsIn values.

View Source
var (
	MockedRepainterImplementation = uuid.NewString()
)

Functions

func Apply

func Apply(ui *UI, ss ...Setting) error

func ContinueExecution added in v0.7.0

func ContinueExecution(bb []bool) func() bool

WantNextRepaintIn creates a closure around given Repainter.Execute return values which can be assigned to Repainter.ContinueExecution.

func ContinueExecutionN added in v0.7.0

func ContinueExecutionN(n int) func() bool

WantNextRepaintIn creates a closure around given Repainter.Execute return values which can be assigned to Repainter.ContinueExecution.

func WantNextRepaintIn added in v0.7.0

func WantNextRepaintIn(dd []time.Duration) func() time.Duration

WantNextRepaintIn creates a closure around given durations which can be assigned to Repainter.WantNextRepaintIn providing the mocked repaint duration of a mocked Repainter.

func WantNextRepaintInD added in v0.7.0

func WantNextRepaintInD(d time.Duration) func() time.Duration

Types

type Call

type Call struct {
	Rune    rune
	Columns int
	Rows    int
	Lyt     backends.Layout
}

type Calls

type Calls []Call

type Ops added in v0.7.0

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

Ops implements backends.Ops.

func (*Ops) AfterDisplay added in v0.7.0

func (oo *Ops) AfterDisplay(rc backends.RepaintController)

AfterDisplay sets a callback which is supposed to be called after painting instructions are painted to the display.

func (*Ops) BeforeDisplay added in v0.7.0

func (oo *Ops) BeforeDisplay(cb func())

BeforeDisplay sets a callback which is supposed to be called before painting instructions are painted to the display.

func (*Ops) Implements added in v0.7.0

func (oo *Ops) Implements(backends.LytFlags, image.Point) backends.LytFlags

Implements is a dummy implementation of backends.Ops.Implements which pretends to implement given ops instance oo set layout flags.

func (Ops) LenPaintedRects added in v0.7.0

func (or Ops) LenPaintedRects() int

func (Ops) LenPaintedRunes added in v0.7.0

func (or Ops) LenPaintedRunes() int

func (*Ops) PaintRect added in v0.7.0

func (oo *Ops) PaintRect(dim image.Rectangle, c backends.Color)

PaintRect is a dummy implementation of backends.Ops.PaintRect which only records the request.

func (*Ops) PaintRune added in v0.7.0

func (oo *Ops) PaintRune(r rune, column, row int, lyt backends.Layout)

PaintRune is a dummy implementation of backends.Ops.PaintRune which only records the request.

func (Ops) PaintedRect added in v0.7.0

func (or Ops) PaintedRect(idx int) Rect

func (Ops) PaintedRune added in v0.7.0

func (or Ops) PaintedRune(idx int) Rune

func (*Ops) SetImplements added in v0.7.0

func (oo *Ops) SetImplements(ff backends.LytFlags) *Ops

func (*Ops) Stat added in v0.7.0

func (oo *Ops) Stat() OpsInfo

Stat reports internal state of given Ops instance oo for testing.

type OpsInfo added in v0.7.0

type OpsInfo struct {
	BeforeDisplay func()
	AfterDisplay  backends.RepaintController
}

type Rect

type Rect struct {
	Dim   image.Rectangle
	Color backends.Color
}

type Rects

type Rects []Rect

type Repainter added in v0.7.0

type Repainter struct {

	// WantNextRepaintsIn are the return values of a repainter mock's
	// subsequent calls of Repainter.WantNextRepaintIn
	WantNextRepaintsIn func() time.Duration

	// ContinueExecution are the return values of a repainter mock's
	// subsequent calls of Repainter.Execute
	ContinueExecution func() bool

	InjectedExecution func(backends.RepaintEnv) (done bool)
	// contains filtered or unexported fields
}

Repainter implements backends.Repainter.

func (*Repainter) BufferCount added in v0.7.0

func (r *Repainter) BufferCount() int

BufferCount reports with how many different buffer instances Repainter.Execute was called.

func (*Repainter) Execute added in v0.7.0

func (r *Repainter) Execute(env backends.RepaintEnv) (done bool)

Execute implements backends.Repainter.Execute and reports the values from given repainter r's ContinueExecution field unless r is out of values or stopped in which case DefaultExecuteDone is reported.

func (*Repainter) ExecuteCount added in v0.7.0

func (r *Repainter) ExecuteCount() int

ExecuteCount reports how many time given repainter r's Execute method was called.

func (*Repainter) ID added in v0.7.0

func (r *Repainter) ID() string

func (*Repainter) IsStopped added in v0.7.0

func (r *Repainter) IsStopped() bool

func (*Repainter) LastBuffer added in v0.7.0

func (r *Repainter) LastBuffer() *backends.DisplayBuffer

func (*Repainter) Origin added in v0.7.0

func (r *Repainter) Origin() (x, y int)

Origin reports the origin set by Repainter.SetOrigin.

func (*Repainter) Replacing added in v0.7.0

func (r *Repainter) Replacing() bool

func (*Repainter) SetID added in v0.7.0

func (r *Repainter) SetID(id string)

func (*Repainter) SetOrigin added in v0.7.0

func (r *Repainter) SetOrigin(x, y uint)

SetOrigin implements backends.Repainter.SetOrigin; Note set value is reported by Repainter.Origin.

func (*Repainter) SetReplacing added in v0.7.0

func (r *Repainter) SetReplacing(isReplacing bool)

func (*Repainter) Stop added in v0.7.0

func (r *Repainter) Stop()

Stop has given repainter r been done in the next repainting cycle.

func (*Repainter) WantNextRepaintIn added in v0.7.0

func (r *Repainter) WantNextRepaintIn() (d time.Duration)

WantNextRepaintIn implements backends.Repainter.WantNextRepaintIn and reports the values from given repainter r's WantNextRepaintsIn field or DefaultExecuteDone if out of values.

func (*Repainter) WantNextRepaintInCount added in v0.7.0

func (r *Repainter) WantNextRepaintInCount() int

WantNextRepaintInCount reports how many times given repainter r's WantNextRepaintsIn method was called.

type Rune

type Rune struct {
	R      rune
	Column int
	Row    int
	Lyt    backends.Layout
}

type Runes

type Runes []Rune

type Setting

type Setting = settingspkg.Setting

func BeforeRepaint added in v0.7.0

func BeforeRepaint(evt backends.Event) Setting

func MergedRepaint added in v0.7.0

func MergedRepaint(evt backends.Event) Setting

func PanicEventPolling

func PanicEventPolling(p any) Setting

func SetImplements

func SetImplements(ff backends.LytFlags) Setting

type UI

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

UI is a backends implementation that reports only self-injected events for testing.

func Register

func Register(ui *UI, scc *settingspkg.Contexts) *UI

Register given mocked ui on given settings context scc. While ui may be nil and is created Register panics if scc is nil.

func (*UI) Apply added in v0.7.0

func (ui *UI) Apply(rc backends.ReConfig)

Apply reconfigures given ui's behavior according to set ReConfig rc.Instructions.

func (*UI) Cleanup

func (ui *UI) Cleanup()

Cleanup implements backend.UIer.Cleanup ensuring that the event polling go routine in vw.loop returns.

func (*UI) Display

func (ui *UI) Display() error

Display blocks the main go routine in production avoiding premature exiting of the main go routine. Hence production Display implementations will never return no matter what. Since this behavior is irrelevant for testing the effort dealing with a blocking vw.Display call can be spared.

func (*UI) Inject

func (ui *UI) Inject(evt backends.Event)

Inject injects given event to the event queue. NOTE Inject blocks until the event is polled! I.e. you can not inject and receive (quit/key) events in the same go routine.

func (*UI) InjectAsync added in v0.7.0

func (ui *UI) InjectAsync(evt backends.Event)

InjectAsync injects given event and returns instantly, i.e. before the event is reported.

func (*UI) InjectAsyncFrame added in v0.7.0

func (ui *UI) InjectAsyncFrame(columns, rows int)

InjectAsyncFrame injects a backends.FrameEvent with given columns and rows counts without waiting for it being reported.

func (*UI) InjectAsyncKey added in v0.7.0

func (ui *UI) InjectAsyncKey(r rune, m backends.KeyModifier)

InjectAsyncFrame injects a backends.KeyEvent with given rune and modifier without waiting for it being reported.

func (*UI) LenPaintCalls

func (ui *UI) LenPaintCalls() int

func (*UI) LenPaintedRects

func (ui *UI) LenPaintedRects() int

LenPaintedRects return the number of rectangle painted by given ui's backends.Ops implementation.

func (*UI) LenPaintedRunes

func (ui *UI) LenPaintedRunes() int

LenPaintedRunes returns the number of runes painted by given ui's backends.Ops implementation.

func (*UI) Paint added in v0.7.0

func (ui *UI) Paint(
	paint backends.Painter,
	lyt backends.Layout,
	column, row int,
	rr ...rune)

func (*UI) PaintCall

func (ui *UI) PaintCall(n int) Call

func (*UI) PaintedRect

func (ui *UI) PaintedRect(n int) Rect

PaintedRect returns the n-th painted rectangle by the backends.Ops implementation of given ui.

func (*UI) PaintedRune

func (ui *UI) PaintedRune(n int) Rune

PaintedRune returns the n-th painted rune by the backends.Ops implementation of given ui.

func (*UI) Poll

func (ui *UI) Poll() backends.Event

Poll implements backend.UIer.Poll mocking an arbitrary ui backend.

func (*UI) Size

func (ui *UI) Size() image.Point

Size reports given ui's currently set size. Note set size is modified by injecting a backends.ResizeEvent. Note a zero columns dimension defaults to mock.ColumnsDefault and a zero rows dimension to mock.RowsDefault.

func (*UI) WaitForPolling

func (ui *UI) WaitForPolling()

WaitForPolling implements backend.UIer.WaitForPolling mocking an WaitForPolling blocks until the event loop starts polling

Jump to

Keyboard shortcuts

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