-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen_test.go
114 lines (101 loc) · 2 KB
/
screen_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package termemu
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
)
func makeScreen(chars []string) *screen {
s := newScreen(&EmptyFrontend{})
s.setSize(len(chars[0]), len(chars))
for i := range chars {
copy(s.chars[i], []rune(chars[i]))
}
if s.size.X != len(chars[0]) || s.size.Y != len(chars) {
panic(fmt.Sprintf("Bad size: %+v", s.size))
}
return s
}
func testScreen(s *screen, chars []string) bool {
for i := range chars {
for j := range chars[i] {
if s.chars[i][j] != rune(chars[i][j]) {
return false
}
}
}
return true
}
var ninePatch = []string{
"112233",
"112233",
"445566",
"445566",
"778899",
"778899",
}
func TestMe(t *testing.T) {
s := makeScreen(ninePatch)
s.rawWriteRunes(1, 1, []rune("asdf"), CRText)
if testScreen(s, ninePatch) {
s.printScreen()
t.Errorf("Expected string to change and testScreen to report false")
}
}
func TestErase(t *testing.T) {
var s *screen
s = makeScreen(ninePatch)
// non-inclusive
s.eraseRegion(Region{X: 1, Y: 1, X2: 5, Y2: 5}, CRClear)
if !testScreen(s, []string{
"112233",
"1 3",
"4 6",
"4 6",
"7 9",
"778899",
}) {
s.printScreen()
t.Errorf("Expected middle of screen to be erased")
}
}
func TestScroll(t *testing.T) {
var s *screen
s = makeScreen(ninePatch)
s.scroll(1, 4, -1)
if !testScreen(s, []string{
"112233",
"445566",
"445566",
"778899",
" ",
"778899",
}) {
s.printScreen()
t.Errorf("Expected screen to scroll up")
}
s = makeScreen(ninePatch)
s.scroll(1, 4, 1)
if !testScreen(s, []string{
"112233",
" ",
"112233",
"445566",
"445566",
"778899",
}) {
s.printScreen()
t.Errorf("Expected screen to scroll down")
}
}
func TestStyledLine(t *testing.T) {
s := makeScreen(ninePatch)
l := s.StyledLine(1, 2, 0)
want := &Line{
Text: []rune{'1', '2'},
Spans: []StyledSpan{StyledSpan{FG: ColDefault, BG: ColDefault, Width: 2}},
Width: 2,
}
if diff := cmp.Diff(l, want); diff != "" {
t.Errorf("s.StyledLine(1, 2, 0) = %#v, want %#v", l, want)
}
}