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 <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2022-03-01 11:44:48 -05:00
committed by Elias Naur
parent 1fa9dd0fd0
commit 9b69233924
+5 -1
View File
@@ -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)
}
})
}
}