1
0
Fork 0

More test coverage
timw4mail/gilo/pipeline/head There was a failure building this commit Details

This commit is contained in:
Timothy Warren 2021-04-01 18:51:52 -04:00
parent 1c424fad74
commit 5cb2047762
3 changed files with 56 additions and 22 deletions

View File

@ -75,6 +75,10 @@ func (e *editor) ProcessKeypress() bool {
return false return false
case key.Enter:
case key.Backspace, key.Ctrl('h'):
case key.Esc: case key.Esc:
// Modifier keys that return ANSI escape sequences // Modifier keys that return ANSI escape sequences
str := parseEscapeSequence() str := parseEscapeSequence()

View File

@ -10,24 +10,52 @@ func TestNew(t *testing.T) {
} }
} }
//type moveCursor struct { type moveCursor struct {
// key string keys []string
// editor *editor withFile bool
//} cursor *point
// }
//var cursorTests = []moveCursor{
// {"\x1b", New()}, var cursorTests = []moveCursor{
//} {[]string{"\x1b"}, false, &point{0,0}},
// {[]string{keyRight}, true, &point{1,0}},
//func TestMoveCursor(t *testing.T) { {[]string{keyEnd}, true, &point{14, 0}},
// for _, test := range cursorTests { {[]string{keyEnd, keyHome}, true, &point{0, 0}},
// e := New() {[]string{keyRight, keyLeft}, true, &point{0, 0}},
// e.moveCursor(test.key) {[]string{keyDown, keyUp}, true, &point{0, 0}},
// want := test.editor {[]string{keyPageUp}, true, &point{0, 0}},
// got := e }
//
// if got != want { func TestMoveCursor(t *testing.T) {
// t.Errorf("Output %v not equal to expected %v for input %q", got, want, test.key) 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)
}
}

View File

@ -5,7 +5,9 @@ package key
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
const ( const (
Esc = '\x1b' Backspace = 0x7f
Esc = 0x1b
Enter = '\r'
) )
// Is this an ASCII character? // Is this an ASCII character?