package gel import ( "image" "image/color" "testing" "github.com/p9c/p9/pkg/gel/fonts/p9fonts" "github.com/p9c/p9/pkg/opts/binary" "github.com/p9c/p9/pkg/opts/meta" "github.com/p9c/p9/pkg/qu" l "github.com/p9c/p9/pkg/gel/gio/layout" "github.com/p9c/p9/pkg/gel/gio/op" ) // testWindow creates a Window suitable for testing without actual GUI. func testWindow(t *testing.T) *Window { t.Helper() quit := qu.T() th := NewTheme( binary.New(meta.Data{}, false, nil), p9fonts.Collection(), quit, ) w := &Window{ Theme: th, scale: &scaledConfig{1}, } th.WidgetPool = w.NewPool() return w } // testContext creates a layout.Context for testing with the given size. func testContext(t *testing.T, size image.Point) l.Context { t.Helper() ops := new(op.Ops) return l.Context{ Ops: ops, Constraints: l.Constraints{ Min: image.Point{}, Max: size, }, } } // assertDimensionsNonZero checks that dimensions have non-zero width and height. func assertDimensionsNonZero(t *testing.T, dims l.Dimensions, msg string) { t.Helper() if dims.Size.X == 0 && dims.Size.Y == 0 { t.Errorf("%s: got zero dimensions", msg) } } // assertDimensionsWithin checks dimensions are within expected bounds. func assertDimensionsWithin(t *testing.T, dims l.Dimensions, maxX, maxY int, msg string) { t.Helper() if dims.Size.X > maxX { t.Errorf("%s: width %d exceeds max %d", msg, dims.Size.X, maxX) } if dims.Size.Y > maxY { t.Errorf("%s: height %d exceeds max %d", msg, dims.Size.Y, maxY) } } // assertColorEqual checks two colors are equal. func assertColorEqual(t *testing.T, got, want color.NRGBA, msg string) { t.Helper() if got != want { t.Errorf("%s: got color %v, want %v", msg, got, want) } } // assertNoError fails the test if err is not nil. func assertNoError(t *testing.T, err error, msg string) { t.Helper() if err != nil { t.Errorf("%s: unexpected error: %v", msg, err) } }