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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
package tui
import (
"testing"
)
func TestRenderHRDefault(t *testing.T) {
buf := NewBuffer(20, 5)
hr := New(WithHR(), WithWidth(10))
hr.Calculate(20, 5)
RenderTree(buf, hr)
for x := range 10 {
cell := buf.Cell(x, 0)
if cell.Rune != '─' {
t.Errorf("HR at x=%d = %q, want '─'", x, cell.Rune)
}
}
for x := 10; x < 20; x++ {
cell := buf.Cell(x, 0)
if cell.Rune != ' ' {
t.Errorf("beyond HR at x=%d = %q, want ' '", x, cell.Rune)
}
}
}
func TestRenderHRDouble(t *testing.T) {
buf := NewBuffer(20, 5)
hr := New(WithHR(), WithWidth(10), WithBorder(BorderDouble))
hr.Calculate(20, 5)
RenderTree(buf, hr)
for x := range 10 {
cell := buf.Cell(x, 0)
if cell.Rune != '═' {
t.Errorf("HR double at x=%d = %q, want '═'", x, cell.Rune)
}
}
}
func TestRenderHRThick(t *testing.T) {
buf := NewBuffer(20, 5)
hr := New(WithHR(), WithWidth(10), WithBorder(BorderThick))
hr.Calculate(20, 5)
RenderTree(buf, hr)
for x := range 10 {
cell := buf.Cell(x, 0)
if cell.Rune != '━' {
t.Errorf("HR thick at x=%d = %q, want '━'", x, cell.Rune)
}
}
}
func TestRenderHRWithColor(t *testing.T) {
buf := NewBuffer(20, 5)
hr := New(
WithHR(),
WithWidth(10),
WithTextStyle(NewStyle().Foreground(Cyan)),
)
hr.Calculate(20, 5)
RenderTree(buf, hr)
for x := range 10 {
cell := buf.Cell(x, 0)
if cell.Rune != '─' {
t.Errorf("HR at x=%d = %q, want '─'", x, cell.Rune)
}
if cell.Style.Fg != Cyan {
t.Errorf("HR style at x=%d Fg = %v, want Cyan", x, cell.Style.Fg)
}
}
}
func TestRenderHRInContainer(t *testing.T) {
buf := NewBuffer(30, 10)
container := New(
WithSize(20, 5),
WithDirection(Column),
)
hr := New(WithHR())
container.AddChild(hr)
container.Calculate(30, 10)
RenderTree(buf, container)
hrRect := hr.Rect()
if hrRect.Width != 20 {
t.Errorf("HR width = %d, want 20 (stretch to fill)", hrRect.Width)
}
for x := range 20 {
cell := buf.Cell(x, 0)
if cell.Rune != '─' {
t.Errorf("HR at x=%d = %q, want '─'", x, cell.Rune)
}
}
}
func TestHRIntrinsicSize(t *testing.T) {
hr := New(WithHR())
w, h := hr.IntrinsicSize()
if w != 0 {
t.Errorf("HR intrinsic width = %d, want 0", w)
}
if h != 1 {
t.Errorf("HR intrinsic height = %d, want 1", h)
}
}
func TestHRIsHR(t *testing.T) {
hr := New(WithHR())
normal := New()
if !hr.IsHR() {
t.Error("WithHR() element.IsHR() = false, want true")
}
if normal.IsHR() {
t.Error("normal element.IsHR() = true, want false")
}
}
func TestRenderHRInScrollableContainer(t *testing.T) {
buf := NewBuffer(30, 10)
container := New(
WithSize(20, 8),
WithDirection(Column),
WithScrollable(ScrollVertical),
WithPadding(1),
)
hr := New(WithHR())
container.AddChild(hr)
container.Calculate(30, 10)
RenderTree(buf, container)
hrRect := hr.Rect()
expectedWidth := 18
if hrRect.Width != expectedWidth {
t.Errorf("HR width = %d, want %d (stretch to fill content area)", hrRect.Width, expectedWidth)
}
for x := 1; x < 19; x++ {
cell := buf.Cell(x, 1)
if cell.Rune != '─' {
t.Errorf("HR at x=%d, y=1 = %q, want '─'", x, cell.Rune)
}
}
}
|