forked from james4k/terminal
-
Notifications
You must be signed in to change notification settings - Fork 7
/
vt_test.go
70 lines (64 loc) · 1.44 KB
/
vt_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package terminal
import (
"io"
"strings"
"testing"
)
func extractStr(t *State, x0, x1, row int) string {
var s []rune
for i := x0; i <= x1; i++ {
c, _, _ := t.Cell(i, row)
s = append(s, c)
}
return string(s)
}
func TestPlainChars(t *testing.T) {
var st State
term, err := Create(&st, nil)
if err != nil {
t.Fatal(err)
}
expected := "Hello world!"
_, err = term.Write([]byte(expected))
if err != nil && err != io.EOF {
t.Fatal(err)
}
actual := extractStr(&st, 0, len(expected)-1, 0)
if expected != actual {
t.Fatal(actual)
}
}
func TestNewline(t *testing.T) {
var st State
term, err := Create(&st, nil)
if err != nil {
t.Fatal(err)
}
expected := "Hello world!\n...and more."
_, err = term.Write([]byte("\033[20h")) // set CRLF mode
if err != nil && err != io.EOF {
t.Fatal(err)
}
_, err = term.Write([]byte(expected))
if err != nil && err != io.EOF {
t.Fatal(err)
}
split := strings.Split(expected, "\n")
actual := extractStr(&st, 0, len(split[0])-1, 0)
actual += "\n"
actual += extractStr(&st, 0, len(split[1])-1, 1)
if expected != actual {
t.Fatal(actual)
}
// A newline with a color set should not make the next line that color,
// which used to happen if it caused a scroll event.
st.moveTo(0, st.rows-1)
_, err = term.Write([]byte("\033[1;37m\n$ \033[m"))
if err != nil && err != io.EOF {
t.Fatal(err)
}
_, fg, bg := st.Cell(st.Cursor())
if fg != DefaultFG {
t.Fatal(st.cur.x, st.cur.y, fg, bg)
}
}