uitest/assert.go
Functions
func AssertColorEqual
func AssertColorEqual(t *testing.T, got, want widget.Color) {
t.Helper()
if !colorsApproxEqual(got, want) {
t.Errorf("color = {R:%.3f, G:%.3f, B:%.3f, A:%.3f}, want {R:%.3f, G:%.3f, B:%.3f, A:%.3f}",
got.R, got.G, got.B, got.A, want.R, want.G, want.B, want.A)
}
}
func AssertCursor
AssertCursor checks that the context cursor matches the expected type.
func AssertCursor(t *testing.T, ctx *MockContext, expected widget.CursorType) {
t.Helper()
if ctx.CursorVal != expected {
t.Errorf("cursor = %v, want %v", ctx.CursorVal, expected)
}
}
func AssertDrawnText
AssertDrawnText checks that the canvas contains at least one DrawText call
with the expected text string. It fails the test if no matching text is found.
func AssertDrawnText(t *testing.T, canvas *MockCanvas, expected string) {
t.Helper()
for _, dt := range canvas.Texts {
if dt.Text == expected {
return
}
}
t.Errorf("expected text %q to be drawn, but it was not found in %d text calls", expected, len(canvas.Texts))
}
func AssertFocused
AssertFocused checks that the given widget currently has focus in the context.
func AssertFocused(t *testing.T, ctx *MockContext, w widget.Widget) {
t.Helper()
if ctx.FocusedVal != w {
t.Errorf("expected widget to be focused, but it is not")
}
}
func AssertInvalidated
AssertInvalidated checks that the context was invalidated at least once.
func AssertInvalidated(t *testing.T, ctx *MockContext) {
t.Helper()
if !ctx.Invalidated {
t.Error("expected context to be invalidated, but it was not")
}
}
func AssertNoDrawnText
AssertNoDrawnText checks that the canvas does not contain a DrawText call
with the given text string. It fails the test if the text is found.
func AssertNoDrawnText(t *testing.T, canvas *MockCanvas, text string) {
t.Helper()
for _, dt := range canvas.Texts {
if dt.Text == text {
t.Errorf("expected text %q to NOT be drawn, but it was found", text)
return
}
}
}
func AssertNotFocused
AssertNotFocused checks that the given widget does NOT have focus.
func AssertNotFocused(t *testing.T, ctx *MockContext, w widget.Widget) {
t.Helper()
if ctx.FocusedVal == w {
t.Errorf("expected widget to NOT be focused, but it is")
}
}
func AssertNotInvalidated
AssertNotInvalidated checks that the context was not invalidated.
func AssertNotInvalidated(t *testing.T, ctx *MockContext) {
t.Helper()
if ctx.Invalidated {
t.Error("expected context to NOT be invalidated, but it was")
}
}
func AssertRectDrawn
AssertRectDrawn checks that a rectangle was drawn at the expected bounds.
It compares using approximate float32 equality.
func AssertRectDrawn(t *testing.T, canvas *MockCanvas, expected geometry.Rect) {
t.Helper()
for _, r := range canvas.Rects {
if rectsApproxEqual(r.Bounds, expected) {
return
}
}
t.Errorf("expected rect %v to be drawn, but it was not found in %d rect calls", expected, len(canvas.Rects))
}
AssertColorEqual checks that two colors are approximately equal
within floating-point tolerance.