forked from zyedidia/terminal
-
Notifications
You must be signed in to change notification settings - Fork 13
/
vt_test.go
64 lines (58 loc) · 1.39 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
package vt10x
import (
"io"
"strings"
"testing"
)
func extractStr(term Terminal, x0, x1, row int) string {
var s []rune
for i := x0; i <= x1; i++ {
attr := term.Cell(i, row)
s = append(s, attr.Char)
}
return string(s)
}
func TestPlainChars(t *testing.T) {
term := New()
expected := "Hello world!"
_, err := term.Write([]byte(expected))
if err != nil && err != io.EOF {
t.Fatal(err)
}
actual := extractStr(term, 0, len(expected)-1, 0)
if expected != actual {
t.Fatal(actual)
}
}
func TestNewline(t *testing.T) {
term := New()
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(term, 0, len(split[0])-1, 0)
actual += "\n"
actual += extractStr(term, 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 := (term.(*terminal))
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)
}
cur := term.Cursor()
attr := term.Cell(cur.X, cur.Y)
if attr.FG != DefaultFG {
t.Fatal(st.cur.X, st.cur.Y, attr.FG, attr.BG)
}
}