forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortcut_test.go
54 lines (40 loc) · 1.34 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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_RemoveShortcut(t *testing.T) {
handler := &ShortcutHandler{}
handler.AddShortcut(&ShortcutCopy{}, func(shortcut Shortcut) {})
handler.AddShortcut(&ShortcutPaste{}, func(shortcut Shortcut) {})
assert.Equal(t, 2, len(handler.entry))
handler.RemoveShortcut(&ShortcutCopy{})
assert.Equal(t, 1, len(handler.entry))
handler.RemoveShortcut(&ShortcutPaste{})
assert.Equal(t, 0, len(handler.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)
}