-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscrollview_test.go
More file actions
116 lines (98 loc) · 2.84 KB
/
scrollview_test.go
File metadata and controls
116 lines (98 loc) · 2.84 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
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
115
116
package glyph
import (
"testing"
)
func TestScrollView_RendersChildren(t *testing.T) {
sv := ScrollView.Grow(1)(
HBox(Text("Alice").Bold(), SpaceW(1), Text("12:30").Dim()),
Text("Hello, how are you?"),
SpaceH(1),
HBox(Text("You").Bold(), SpaceW(1), Text("12:35").Dim()),
Text("Good thanks!"),
)
screen := NewBuffer(40, 10)
tmpl := Build(VBox(sv))
tmpl.Execute(screen, 40, 10)
if got := screen.GetLine(0); got != "Alice 12:30" {
t.Errorf("line 0: got %q, want %q", got, "Alice 12:30")
}
if got := screen.GetLine(1); got != "Hello, how are you?" {
t.Errorf("line 1: got %q, want %q", got, "Hello, how are you?")
}
if got := screen.GetLine(3); got != "You 12:35" {
t.Errorf("line 3: got %q, want %q", got, "You 12:35")
}
if got := screen.GetLine(4); got != "Good thanks!" {
t.Errorf("line 4: got %q, want %q", got, "Good thanks!")
}
}
func TestScrollView_StyledAttributes(t *testing.T) {
sv := ScrollView.Grow(1)(
Text("bold").Bold(),
Text("dim").Dim(),
)
screen := NewBuffer(20, 5)
tmpl := Build(VBox(sv))
tmpl.Execute(screen, 20, 5)
cell := screen.Get(0, 0)
if cell.Rune != 'b' || cell.Style.Attr&AttrBold == 0 {
t.Errorf("(0,0): rune=%c bold=%v, want 'b' bold=true", cell.Rune, cell.Style.Attr&AttrBold != 0)
}
cell = screen.Get(0, 1)
if cell.Rune != 'd' || cell.Style.Attr&AttrDim == 0 {
t.Errorf("(0,1): rune=%c dim=%v, want 'd' dim=true", cell.Rune, cell.Style.Attr&AttrDim != 0)
}
}
func TestScrollView_ScrollsContent(t *testing.T) {
// content taller than viewport
sv := ScrollView.Grow(1)(
Text("line0"),
Text("line1"),
Text("line2"),
Text("line3"),
Text("line4"),
Text("line5"),
Text("line6"),
Text("line7"),
)
screen := NewBuffer(20, 4)
tmpl := Build(VBox(sv))
tmpl.Execute(screen, 20, 4)
// initially shows top
if got := screen.GetLine(0); got != "line0" {
t.Errorf("before scroll line 0: got %q, want %q", got, "line0")
}
if got := screen.GetLine(3); got != "line3" {
t.Errorf("before scroll line 3: got %q, want %q", got, "line3")
}
// scroll down
sv.Layer().ScrollDown(2)
screen.ClearDirty()
tmpl.Execute(screen, 20, 4)
if got := screen.GetLine(0); got != "line2" {
t.Errorf("after scroll line 0: got %q, want %q", got, "line2")
}
if got := screen.GetLine(3); got != "line5" {
t.Errorf("after scroll line 3: got %q, want %q", got, "line5")
}
}
func TestScrollView_Refresh(t *testing.T) {
content := "original"
sv := ScrollView.Grow(1)(
Text(&content),
)
screen := NewBuffer(20, 5)
tmpl := Build(VBox(sv))
tmpl.Execute(screen, 20, 5)
if got := screen.GetLine(0); got != "original" {
t.Errorf("before refresh: got %q, want %q", got, "original")
}
// change content and refresh
content = "updated"
sv.Refresh()
screen.ClearDirty()
tmpl.Execute(screen, 20, 5)
if got := screen.GetLine(0); got != "updated" {
t.Errorf("after refresh: got %q, want %q", got, "updated")
}
}