mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
io/pointer: print all types in Type.String
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
@@ -265,6 +265,22 @@ func (op InputOp) Add(o *op.Ops) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t Type) String() string {
|
func (t Type) String() string {
|
||||||
|
if t == Cancel {
|
||||||
|
return "Cancel"
|
||||||
|
}
|
||||||
|
var buf strings.Builder
|
||||||
|
for tt := Type(1); tt > 0; tt <<= 1 {
|
||||||
|
if t&tt > 0 {
|
||||||
|
if buf.Len() > 0 {
|
||||||
|
buf.WriteByte('|')
|
||||||
|
}
|
||||||
|
buf.WriteString((t & tt).string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t Type) string() string {
|
||||||
switch t {
|
switch t {
|
||||||
case Press:
|
case Press:
|
||||||
return "Press"
|
return "Press"
|
||||||
|
|||||||
@@ -8,6 +8,32 @@ import (
|
|||||||
"gioui.org/op"
|
"gioui.org/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestTypeString(t *testing.T) {
|
||||||
|
for _, tc := range []struct {
|
||||||
|
typ Type
|
||||||
|
res string
|
||||||
|
}{
|
||||||
|
{Cancel, "Cancel"},
|
||||||
|
{Press, "Press"},
|
||||||
|
{Release, "Release"},
|
||||||
|
{Move, "Move"},
|
||||||
|
{Drag, "Drag"},
|
||||||
|
{Enter, "Enter"},
|
||||||
|
{Leave, "Leave"},
|
||||||
|
{Scroll, "Scroll"},
|
||||||
|
{Enter | Leave, "Enter|Leave"},
|
||||||
|
{Press | Release, "Press|Release"},
|
||||||
|
{Enter | Leave | Press | Release, "Press|Release|Enter|Leave"},
|
||||||
|
{Move | Scroll, "Move|Scroll"},
|
||||||
|
} {
|
||||||
|
t.Run(tc.res, func(t *testing.T) {
|
||||||
|
if want, got := tc.res, tc.typ.String(); want != got {
|
||||||
|
t.Errorf("got %q; want %q", got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTransformChecks(t *testing.T) {
|
func TestTransformChecks(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err == nil {
|
if err := recover(); err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user