package editor import ( "testing" "timshome.page/gilo/char" gilo2 "timshome.page/gilo/internal/gilo" ) type moveCursor struct { keys []string withFile bool cursor *gilo2.Point } var cursorTests = []moveCursor{ {[]string{string(char.Esc)}, false, gilo2.DefaultPoint()}, {[]string{keyRight}, true, gilo2.NewPoint(1, 0)}, {[]string{keyDown, keyEnd}, true, gilo2.NewPoint(14, 1)}, {[]string{keyEnd, keyHome}, true, gilo2.DefaultPoint()}, {[]string{keyRight, keyLeft}, true, gilo2.DefaultPoint()}, {[]string{keyDown, keyUp}, true, gilo2.DefaultPoint()}, // {[]string{keyPageUp}, true, gilo.DefaultPoint()}, } func TestMoveCursor(t *testing.T) { for _, test := range cursorTests { e := NewEditor() if test.withFile { e.Open("Editor.go") } for _, k := range test.keys { e.moveCursor(k) } 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(char.Esc)}, {"XZ", string(char.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) } } }