Слияние кода завершено, страница обновится автоматически
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 )