Timothy J. Warren
6255936e35
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
78 lines
1.5 KiB
Go
78 lines
1.5 KiB
Go
package editor
|
|
|
|
import (
|
|
"testing"
|
|
"timshome.page/gilo/key"
|
|
)
|
|
|
|
type moveCursor struct {
|
|
keys []string
|
|
withFile bool
|
|
cursor *point
|
|
}
|
|
|
|
var cursorTests = []moveCursor{
|
|
{[]string{"\x1b"}, false, &point{0, 0}},
|
|
{[]string{keyRight}, true, &point{1, 0}},
|
|
{[]string{keyEnd}, true, &point{14, 0}},
|
|
{[]string{keyEnd, keyHome}, true, &point{0, 0}},
|
|
{[]string{keyRight, keyLeft}, true, &point{0, 0}},
|
|
{[]string{keyDown, keyUp}, true, &point{0, 0}},
|
|
// {[]string{keyPageUp}, true, &point{0, 0}},
|
|
}
|
|
|
|
func TestMoveCursor(t *testing.T) {
|
|
for _, test := range cursorTests {
|
|
e := New()
|
|
|
|
if test.withFile {
|
|
e.Open("editor.go")
|
|
}
|
|
|
|
for _, key := range test.keys {
|
|
e.moveCursor(key)
|
|
}
|
|
want := test.cursor
|
|
got := e.cursor
|
|
|
|
if got.x != want.x || got.y != want.y {
|
|
t.Errorf("Output %v not equal to expected %v for input %q", got, want, test.keys)
|
|
}
|
|
}
|
|
}
|
|
|
|
type seqTest struct {
|
|
input string
|
|
expected string
|
|
}
|
|
|
|
var seqTests = []seqTest{
|
|
{"OH", keyHome},
|
|
{"OF", keyEnd},
|
|
{"[A", keyUp},
|
|
{"[B", keyDown},
|
|
{"[C", keyRight},
|
|
{"[D", keyLeft},
|
|
{"[H", keyHome},
|
|
{"[F", keyEnd},
|
|
{"[1~", keyHome},
|
|
{"[3~", keyDelete},
|
|
{"[4~", keyEnd},
|
|
{"[5~", keyPageUp},
|
|
{"[6~", keyPageDown},
|
|
{"[7~", keyHome},
|
|
{"[8~", keyEnd},
|
|
{"OQ", string(rune(key.Esc))},
|
|
}
|
|
|
|
func TestEscToKey(t *testing.T) {
|
|
for _, test := range seqTests {
|
|
got := escSeqToKey([]rune(test.input))
|
|
want := test.expected
|
|
|
|
if got != want {
|
|
t.Errorf("Got %s for input %s, expected %s", got, test.input, want)
|
|
}
|
|
}
|
|
}
|