gilo/editor/input_test.go
Timothy Warren 38d127e419
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
Split input handling from editor.go
2021-04-02 12:03:33 -04:00

40 lines
844 B
Go

package editor
import "testing"
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)
}
}
}