akiyosi.goneovim/editor/input_linux_test.go

154 lines
4.7 KiB
Go
Raw Permalink Normal View History

2023-07-16 00:53:36 +09:00
//go:build linux
2020-03-25 00:13:14 +09:00
// +build linux
package editor
import (
"fmt"
"testing"
2023-07-16 00:53:36 +09:00
"github.com/akiyosi/qt/core"
"github.com/akiyosi/qt/gui"
2020-03-25 00:13:14 +09:00
)
2020-03-24 09:12:35 -07:00
func TestLinuxEditor_convertKey(t *testing.T) {
2020-03-25 00:13:14 +09:00
tests := []struct {
2020-09-26 12:04:36 +09:00
name string
args *gui.QKeyEvent
want string
2020-03-25 00:13:14 +09:00
}{
{
`convertKey() Linux LessThan modifier keys 1`,
2020-09-26 12:04:36 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_Less), core.Qt__ShiftModifier|core.Qt__ControlModifier, "<", false, 1),
2020-03-24 09:12:35 -07:00
"<C-lt>",
2020-03-25 00:13:14 +09:00
},
{
`convertKey() Linux LessThan modifier keys 2`,
2020-09-26 12:04:36 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_Less), core.Qt__ShiftModifier|core.Qt__AltModifier, "<", false, 1),
2020-03-25 00:13:14 +09:00
"<A-lt>",
},
{
`convertKey() Linux LessThan modifier keys 3`,
2020-09-26 12:04:36 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_Less), core.Qt__ShiftModifier|core.Qt__MetaModifier, "<", false, 1),
2020-03-24 09:12:35 -07:00
"<D-lt>",
2020-03-25 00:13:14 +09:00
},
2021-07-25 22:35:17 +09:00
{
`convertKey() Linux Ctrl Caret WellFormed 1`,
2022-09-23 00:35:20 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_6), core.Qt__ControlModifier, string("\u001E"), false, 1),
2021-07-25 22:35:17 +09:00
"<C-^>",
},
{
`convertKey() Linux Ctrl Caret WellFormed 2`,
2022-09-23 00:35:20 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_AsciiCircum), core.Qt__ShiftModifier|core.Qt__ControlModifier, string("\u001E"), false, 1),
2021-07-25 22:35:17 +09:00
"<C-^>",
},
{
`convertKey() Linux Ctrl Caret WellFormed 3`,
2022-09-23 00:35:20 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_AsciiCircum), core.Qt__ShiftModifier|core.Qt__ControlModifier|core.Qt__MetaModifier, string("\u001E"), false, 1),
2021-07-25 22:35:17 +09:00
"<C-^>",
},
{
`convertKey() Linux ShiftModifier Letter 1`,
2022-09-23 00:35:20 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_B), core.Qt__ControlModifier, string("\u0002"), false, 1),
2021-07-25 22:35:17 +09:00
"<C-b>",
},
{
`convertKey() Linux ShiftModifier Letter 2`,
2022-09-23 00:35:20 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_B), core.Qt__ShiftModifier|core.Qt__ControlModifier, string("\u0002"), false, 1),
2021-07-25 22:35:17 +09:00
"<C-S-B>",
},
2021-07-30 12:01:15 +09:00
{
`convertKey() Linux German keyboardlayout 1`,
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_BraceLeft), core.Qt__GroupSwitchModifier, "{", false, 1),
"{",
},
{
`convertKey() Linux German keyboardlayout 2`,
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_BracketLeft), core.Qt__GroupSwitchModifier, "[", false, 1),
"[",
},
{
`convertKey() Linux German keyboardlayout 3`,
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_BracketRight), core.Qt__GroupSwitchModifier, "]", false, 1),
"]",
},
{
`convertKey() Linux German keyboardlayout 4`,
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_BraceRight), core.Qt__GroupSwitchModifier, "}", false, 1),
"}",
},
{
`convertKey() Linux German keyboardlayout 5`,
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_At), core.Qt__GroupSwitchModifier, "@", false, 1),
"@",
},
{
`convertKey() Linux German keyboardlayout 6`,
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_Backslash), core.Qt__GroupSwitchModifier, "\\", false, 1),
"<Bslash>",
},
{
`convertKey() Linux German keyboardlayout 7`,
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_AsciiTilde), core.Qt__GroupSwitchModifier, "~", false, 1),
"~",
},
{
`convertKey() Linux Control+Space`,
2022-09-23 00:35:20 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_Space), core.Qt__ControlModifier, string("\u0000"), false, 1),
"<C-Space>",
},
2024-01-26 10:14:22 +09:00
{
`convertKey() Linux Spanish keyboardlayout 1`,
gui.NewQKeyEvent(core.QEvent__KeyPress, int(core.Qt__Key_BracketLeft), core.Qt__GroupSwitchModifier, string("["), false, 1),
"[",
},
2020-03-25 00:13:14 +09:00
}
e := &Editor{}
e.InitSpecialKeys()
for key, value := range e.specialKeys {
2024-01-26 10:14:22 +09:00
text := ""
if key == core.Qt__Key_Space {
text = " "
}
2020-03-25 00:13:14 +09:00
tests = append(
tests,
[]struct {
2020-09-26 12:04:36 +09:00
name string
args *gui.QKeyEvent
want string
2020-03-25 00:13:14 +09:00
}{
{
`convertKey() Linux special keys`,
2024-01-26 10:14:22 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(key), core.Qt__NoModifier, text, false, 1),
2020-03-25 00:13:14 +09:00
fmt.Sprintf("<%s>", value),
},
{
`convertKey() Linux special keys with Ctrl`,
2024-01-26 10:14:22 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(key), core.Qt__ControlModifier, text, false, 1),
2020-03-24 09:12:35 -07:00
fmt.Sprintf("<C-%s>", value),
2020-03-25 00:13:14 +09:00
},
{
`convertKey() Linux special keys with Alt`,
2024-01-26 10:14:22 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(key), core.Qt__AltModifier, text, false, 1),
2020-03-25 00:13:14 +09:00
fmt.Sprintf("<A-%s>", value),
},
{
`convertKey() Linux special keys with Meta`,
2024-01-26 10:14:22 +09:00
gui.NewQKeyEvent(core.QEvent__KeyPress, int(key), core.Qt__MetaModifier, text, false, 1),
2020-03-24 09:12:35 -07:00
fmt.Sprintf("<D-%s>", value),
2020-03-25 00:13:14 +09:00
},
}...,
)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := e.convertKey(tt.args); got != tt.want {
t.Errorf("Editor.convertKey() = %v, want %v", got, tt.want)
}
})
}
}