forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcut_test.go
47 lines (36 loc) · 1.23 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
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
})
assert.True(t, handle.TypedShortcut(&ShortcutCut{}))
assert.True(t, cutCalled)
assert.True(t, handle.TypedShortcut(&ShortcutCopy{}))
assert.True(t, copyCalled)
assert.True(t, handle.TypedShortcut(&ShortcutPaste{}))
assert.True(t, pasteCalled)
}
func TestShortcutHandler_HandleShortcut_Failures(t *testing.T) {
handle := &ShortcutHandler{}
handle.AddShortcut(&ShortcutPaste{}, func(shortcut Shortcut) {})
assert.False(t, handle.TypedShortcut(nil))
assert.False(t, handle.TypedShortcut(&ShortcutCut{}))
}