io/input: tighten tests

Now that event delivery can be interleaved with commands, tests can be
made more precise.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-11-27 11:30:34 -06:00
parent ed0d5d5767
commit 20c28ef282
6 changed files with 277 additions and 496 deletions
+1 -12
View File
@@ -37,19 +37,14 @@ func TestClickable(t *testing.T) {
layout()
r.Frame(gtx.Ops)
}
// frame: request focus for button 1
gtx.Execute(key.FocusCmd{Tag: &b1})
frame()
// frame: gain focus for button 1
frame()
if !b1.Focused() {
t.Error("button 1 did not gain focus")
}
if b2.Focused() {
t.Error("button 2 should not have focus")
}
// frame: press & release return
frame()
r.Queue(
key.Event{
Name: key.NameReturn,
@@ -66,21 +61,17 @@ func TestClickable(t *testing.T) {
if b2.Clicked(gtx) {
t.Error("button 2 got clicked when it did not have focus")
}
// frame: press return down
r.Queue(
key.Event{
Name: key.NameReturn,
State: key.Press,
},
)
frame()
if b1.Clicked(gtx) {
t.Error("button 1 got clicked, even if it only got return press")
}
// frame: request focus for button 2
gtx.Execute(key.FocusCmd{Tag: &b2})
frame()
// frame: gain focus for button 2
gtx.Execute(key.FocusCmd{Tag: &b2})
frame()
if b1.Focused() {
t.Error("button 1 should not have focus")
@@ -88,14 +79,12 @@ func TestClickable(t *testing.T) {
if !b2.Focused() {
t.Error("button 2 did not gain focus")
}
// frame: release return
r.Queue(
key.Event{
Name: key.NameReturn,
State: key.Release,
},
)
frame()
if b1.Clicked(gtx) {
t.Error("button 1 got clicked, even if it had lost focus")
}
+1 -1
View File
@@ -902,11 +902,11 @@ g 2 4 6 8 g
var tim time.Duration
selected := func(start, end int) string {
gtx.Execute(key.FocusCmd{Tag: e})
// Layout once with no events; populate e.lines.
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
e.Events() // throw away any events from this layout
gtx.Execute(key.FocusCmd{Tag: e})
r.Frame(gtx.Ops)
gtx.Source = r.Source()
// Build the selection events