forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 1
/
shortcut_test.go
63 lines (48 loc) · 1.49 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
55
56
57
58
59
60
61
62
63
package fyne
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func syncMapLen(m *sync.Map) (n int) {
m.Range(func(_, _ interface{}) bool {
n++
return true
})
return
}
func TestShortcutHandler_AddShortcut(t *testing.T) {
handle := &ShortcutHandler{}
handle.AddShortcut(&ShortcutCopy{}, func(shortcut Shortcut) {})
handle.AddShortcut(&ShortcutPaste{}, func(shortcut Shortcut) {})
assert.Equal(t, 2, syncMapLen(&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, syncMapLen(&handler.entry))
handler.RemoveShortcut(&ShortcutCopy{})
assert.Equal(t, 1, syncMapLen(&handler.entry))
handler.RemoveShortcut(&ShortcutPaste{})
assert.Equal(t, 0, syncMapLen(&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)
}