mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-05-04 22:17:48 +08:00
add anko keybinding test
This commit is contained in:
parent
294e9c3604
commit
8e62af32a8
17
anko/anko.go
17
anko/anko.go
@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/mattn/anko/vm"
|
"github.com/mattn/anko/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Anko struct {
|
type Anko struct {
|
||||||
env *env.Env
|
env *env.Env
|
||||||
}
|
}
|
||||||
@ -102,18 +101,18 @@ func (a *Anko) KeybindExists(panel string, eventKey *tcell.EventKey) bool {
|
|||||||
|
|
||||||
if strings.Contains(name, "Ctrl") {
|
if strings.Contains(name, "Ctrl") {
|
||||||
key := extractCtrlRune(name)
|
key := extractCtrlRune(name)
|
||||||
src = fmt.Sprintf("Keybinds.%s.ctrl_%s",
|
src = fmt.Sprintf("Keybinds.%s[\"ctrl_%s\"]",
|
||||||
panel, strings.ToLower(string(key)))
|
panel, strings.ToLower(string(key)))
|
||||||
|
|
||||||
} else if strings.Contains(name, "Alt") {
|
} else if strings.Contains(name, "Alt") {
|
||||||
key := extractAltRune(name)
|
key := extractAltRune(name)
|
||||||
src = fmt.Sprintf("Keybinds.%s.alt_%c", panel, key)
|
src = fmt.Sprintf("Keybinds.%s[\"alt_%c\"]", panel, key)
|
||||||
|
|
||||||
} else if strings.Contains(name, "Rune") {
|
} else if strings.Contains(name, "Rune") {
|
||||||
src = fmt.Sprintf("Keybinds.%s.%c", panel, eventKey.Rune())
|
src = fmt.Sprintf("Keybinds.%s[\"%c\"]", panel, eventKey.Rune())
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
src = fmt.Sprintf("Keybinds.%s.%s", panel, strings.ToLower(name))
|
src = fmt.Sprintf("Keybinds.%s[\"%s\"]", panel, strings.ToLower(name))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,18 +132,18 @@ func (a *Anko) ExecKeybind(panel string, eventKey *tcell.EventKey) error {
|
|||||||
|
|
||||||
if strings.Contains(name, "Ctrl") {
|
if strings.Contains(name, "Ctrl") {
|
||||||
key := extractCtrlRune(name)
|
key := extractCtrlRune(name)
|
||||||
src = fmt.Sprintf("Keybinds.%s.ctrl_%s()",
|
src = fmt.Sprintf("Keybinds.%s[\"ctrl_%s\"]()",
|
||||||
panel, strings.ToLower(string(key)))
|
panel, strings.ToLower(string(key)))
|
||||||
|
|
||||||
} else if strings.Contains(name, "Alt") {
|
} else if strings.Contains(name, "Alt") {
|
||||||
key := extractAltRune(name)
|
key := extractAltRune(name)
|
||||||
src = fmt.Sprintf("Keybinds.%s.alt_%c()", panel, key)
|
src = fmt.Sprintf("Keybinds.%s[\"alt_%c\"]()", panel, key)
|
||||||
|
|
||||||
} else if strings.Contains(name, "Rune") {
|
} else if strings.Contains(name, "Rune") {
|
||||||
src = fmt.Sprintf("Keybinds.%s.%c()", panel, eventKey.Rune())
|
src = fmt.Sprintf("Keybinds.%s[\"%c\"]()", panel, eventKey.Rune())
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
src = fmt.Sprintf("Keybinds.%s.%s()", panel, strings.ToLower(name))
|
src = fmt.Sprintf("Keybinds.%s[\"%s\"]()", panel, strings.ToLower(name))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package anko
|
package anko
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -146,4 +148,96 @@ func TestExtractAltRune(t *testing.T) {
|
|||||||
|
|
||||||
func TestKeybindExists(t *testing.T) {
|
func TestKeybindExists(t *testing.T) {
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
panel string
|
||||||
|
key *tcell.EventKey
|
||||||
|
exists bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
panel: "global",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyRune, 'b', tcell.ModNone),
|
||||||
|
exists: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
panel: "global",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyRune, 'x', tcell.ModNone),
|
||||||
|
exists: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
panel: "global",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyRune, ']', tcell.ModNone),
|
||||||
|
exists: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
panel: "global",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyRune, '[', tcell.ModNone),
|
||||||
|
exists: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
panel: "global",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyCtrlB, 'b', tcell.ModCtrl),
|
||||||
|
exists: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
panel: "global",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyCtrlC, 'c', tcell.ModCtrl),
|
||||||
|
exists: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
panel: "playlist",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyRune, '!', tcell.ModAlt),
|
||||||
|
exists: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
panel: "playlist",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyRune, '>', tcell.ModAlt),
|
||||||
|
exists: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
panel: "playlist",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyCtrlCarat, '^', tcell.ModCtrl),
|
||||||
|
exists: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
panel: "queue",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyRune, '>', tcell.ModAlt),
|
||||||
|
exists: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
panel: "queue",
|
||||||
|
key: tcell.NewEventKey(tcell.KeyEnter, 0, tcell.ModNone),
|
||||||
|
exists: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
src := `
|
||||||
|
module Keybinds {
|
||||||
|
global = {}
|
||||||
|
playlist = {}
|
||||||
|
queue = {}
|
||||||
|
|
||||||
|
global["b"] = func() { return 0 }
|
||||||
|
global["]"] = func() { return 0 }
|
||||||
|
global["ctrl_b"] = func() { return 0 }
|
||||||
|
global["alt_b"] = func() { return 0 }
|
||||||
|
|
||||||
|
playlist["alt_!"] = func() { return 0 }
|
||||||
|
playlist["ctrl_^"] = func() { return 0 }
|
||||||
|
|
||||||
|
queue["alt_>"] = func() { return 0 }
|
||||||
|
queue["enter"] = func() { return 0 }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
a := NewAnko()
|
||||||
|
|
||||||
|
_, err := a.Execute(src)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, test := range tests {
|
||||||
|
got := a.KeybindExists(test.panel, test.key)
|
||||||
|
msg := fmt.Sprintf("error on test %d", i+1)
|
||||||
|
assert.Equal(t, test.exists, got, msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user