1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/mirrors-Fyne

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
shortcut_test.go 1.5 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Jacob Отправлено 02.01.2024 14:24 ca81ae5
package fyne
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func syncMapLen(m *sync.Map) (n int) {
m.Range(func(_, _ any) 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)
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/mirrors-Fyne.git
git@api.gitlife.ru:oschina-mirror/mirrors-Fyne.git
oschina-mirror
mirrors-Fyne
mirrors-Fyne
master