forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortcut_test.go
38 lines (30 loc) · 945 Bytes
/
shortcut_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package fyne
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestShortcutHandler_AddShortcut(t *testing.T) {
handle := &ShortcutHandler{}
handle.AddShortcut(&ShortcutCopy{}, func(shortcut Shortcut) {})
handle.AddShortcut(&ShortcutPaste{}, func(shortcut Shortcut) {})
assert.Equal(t, 2, len(handle.entry))
}
func TestShortcutHandler_HandleShortcut(t *testing.T) {
handle := &ShortcutHandler{}
cutCalled, copyCalled, pasteCalled := false, false, false
handle.AddShortcut(&ShortcutCut{}, func(shortcut Shortcut) {
cutCalled = true
})
handle.AddShortcut(&ShortcutCopy{}, func(shortcut Shortcut) {
copyCalled = true
})
handle.AddShortcut(&ShortcutPaste{}, func(shortcut Shortcut) {
pasteCalled = true
})
handle.TypedShortcut(&ShortcutCut{})
assert.True(t, cutCalled)
handle.TypedShortcut(&ShortcutCopy{})
assert.True(t, copyCalled)
handle.TypedShortcut(&ShortcutPaste{})
assert.True(t, pasteCalled)
}