forked from c-bata/go-prompt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
emacs_test.go
37 lines (31 loc) · 886 Bytes
/
emacs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package prompt
import (
"testing"
istrings "github.com/elk-language/go-prompt/strings"
)
func TestEmacsKeyBindings(t *testing.T) {
p := New(NoopExecutor)
buf := p.buffer
buf.InsertTextMoveCursor("abcde", DefColCount, DefRowCount, false)
if buf.cursorPosition != istrings.RuneNumber(len("abcde")) {
t.Errorf("Want %d, but got %d", len("abcde"), buf.cursorPosition)
}
// Go to the beginning of the line
applyEmacsKeyBind(p, ControlA)
if buf.cursorPosition != 0 {
t.Errorf("Want %d, but got %d", 0, buf.cursorPosition)
}
// Go to the end of the line
applyEmacsKeyBind(p, ControlE)
if buf.cursorPosition != istrings.RuneNumber(len("abcde")) {
t.Errorf("Want %d, but got %d", len("abcde"), buf.cursorPosition)
}
}
func applyEmacsKeyBind(p *Prompt, key Key) {
for i := range emacsKeyBindings {
kb := emacsKeyBindings[i]
if kb.Key == key {
kb.Fn(p)
}
}
}