gilo/editor/editor_test.go

61 lines
1.2 KiB
Go
Raw Normal View History

2021-03-31 19:17:04 -04:00
package editor
import "testing"
func TestNew(t *testing.T) {
e := New()
if e == nil {
t.Errorf("Failed to create editor")
}
}
2021-04-01 18:51:52 -04:00
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)
}
}
}
func TestInsertChar(t *testing.T) {
e := New()
e.insertChar('q')
if e.document.rowCount() != 1 {
t.Errorf("A row was not created when the character was inserted")
}
row := e.document.rows[0]
if row.size() != 1 {
t.Errorf("Failed to add character to row. Row: %v", row)
}
}