-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgommand_test.go
50 lines (44 loc) · 1.1 KB
/
gommand_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
38
39
40
41
42
43
44
45
46
47
48
49
50
package readline_test
import (
"context"
"io"
"strings"
"testing"
"github.com/nyaosorg/go-readline-ny"
"github.com/nyaosorg/go-readline-ny/auto"
)
const f = "\U0001F468\u200D\U0001F33E"
func tryAll(t *testing.T, texts ...string) (string, []string) {
var buffer strings.Builder
editor := readline.Editor{
Tty: &auto.Pilot{texts},
Writer: &buffer,
PromptWriter: func(w io.Writer) (int, error) { return 0, nil },
}
result, err := editor.ReadLine(context.Background())
if err != nil {
t.Fatalf("ERR=%s", err.Error())
return "", nil
}
outputPieces := strings.Split(buffer.String(), "\x1B[?25h\x1B[?25l")
for i, s := range outputPieces {
s = strings.ReplaceAll(s, "\x1B[?25h", "")
s = strings.ReplaceAll(s, "\x1B[?25l", "")
s = strings.ReplaceAll(s, "\u200D", "<ZWJ>")
s = strings.ReplaceAll(s, "\x1B", "<ESC>")
outputPieces[i] = s
}
return result, outputPieces
}
func TestKeyFuncBackSpace(t *testing.T) {
result, outputs := tryAll(t, f, "\b", "x")
if result != "x" {
t.Fatalf("TEXT=%s", result)
return
}
if false {
for _, o := range outputs {
println(o)
}
}
}