From 9b69233924e5dd8aa400e992f600099f2e861a89 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Tue, 1 Mar 2022 11:44:48 -0500 Subject: [PATCH] widget: test caret coordinates This commit adds a check that caret coordinates never exceed the max constraints of the editor. Signed-off-by: Chris Waldon --- widget/editor_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/widget/editor_test.go b/widget/editor_test.go index 67ac0e49..b35f1eac 100644 --- a/widget/editor_test.go +++ b/widget/editor_test.go @@ -35,7 +35,7 @@ func TestEditorConfigurations(t *testing.T) { cache := text.NewCache(gofont.Collection()) fontSize := unit.Px(10) font := text.Font{} - sentence := "the quick brown fox jumps over the lazy dog" + sentence := "\n\n\n\n\n\n\n\n\n\n\n\nthe quick brown fox jumps over the lazy dog" runes := len([]rune(sentence)) // Ensure that both ends of the text are reachable in all permutations @@ -56,6 +56,10 @@ func TestEditorConfigurations(t *testing.T) { e.Layout(gtx, cache, font, fontSize, nil) e.SetCaret(runes, runes) e.Layout(gtx, cache, font, fontSize, nil) + coords := e.CaretCoords() + if int(coords.X) > gtx.Constraints.Max.X || int(coords.Y) > gtx.Constraints.Max.Y { + t.Errorf("caret coordinates %v exceed constraints %v", coords, gtx.Constraints.Max) + } }) } }