-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshiftenter_test.go
More file actions
54 lines (48 loc) · 1.75 KB
/
Copy pathshiftenter_test.go
File metadata and controls
54 lines (48 loc) · 1.75 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"testing"
)
func TestTranslateShiftEnterRewritesCsiU(t *testing.T) {
cases := map[string]struct {
in string
rest string
out string
}{
"shift+enter becomes alt+enter": {"\x1b[13;2u", "", "\x1b\r"},
"alt+shift+enter becomes alt+enter": {"\x1b[13;4u", "", "\x1b\r"},
"xterm encoding is understood too": {"\x1b[27;2;13~", "", "\x1b\r"},
"plain enter is left alone": {"\r", "", "\r"},
"escape is left alone": {"\x1b", "", "\x1b"},
"ctrl+c is left alone": {"\x03", "", "\x03"},
"enter without shift is left alone": {"\x1b[13;5u", "", "\x1b[13;5u"},
"other csi sequences pass through": {"\x1b[1;5A", "", "\x1b[1;5A"},
"text around a sequence survives": {"ab\x1b[13;2ucd", "", "ab\x1b\rcd"},
"a split sequence is held back": {"ab\x1b[13;", "\x1b[13;", "ab"},
"a split escape is not held back": {"ab\x1b", "", "ab\x1b"},
}
for name, testCase := range cases {
t.Run(name, func(t *testing.T) {
rest, out := translateShiftEnter([]byte(testCase.in), nil)
if string(rest) != testCase.rest {
t.Errorf("rest: got %q, want %q", rest, testCase.rest)
}
if string(out) != testCase.out {
t.Errorf("out: got %q, want %q", out, testCase.out)
}
})
}
}
func TestTranslateShiftEnterAcrossReads(t *testing.T) {
var buffer, pending []byte
buffer, pending = translateShiftEnter(append(buffer, "hi\x1b[13"...), pending)
if string(pending) != "hi" {
t.Fatalf("first read: got %q, want %q", pending, "hi")
}
buffer, pending = translateShiftEnter(append(buffer, ";2u!"...), pending)
if string(buffer) != "" {
t.Errorf("buffer should be drained, got %q", buffer)
}
if string(pending) != "hi\x1b\r!" {
t.Errorf("second read: got %q, want %q", pending, "hi\x1b\r!")
}
}