-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdyn_width_zero_test.go
More file actions
54 lines (46 loc) · 1.49 KB
/
Copy pathdyn_width_zero_test.go
File metadata and controls
54 lines (46 loc) · 1.49 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
package glyph
import (
"strings"
"testing"
)
// a PRESENT dynamic width binding evaluating to 0 means "explicitly sized,
// currently zero" — it must not fall into implicit row flex and grab a share.
func TestDynWidthZeroIsNotFlexEligible(t *testing.T) {
spacer := int16(0)
label := "content"
tmpl := Build(HBox(
VBox.Width(&spacer)(Text("X")),
VBox(Text(&label)),
))
buf := NewBuffer(40, 3)
tmpl.Execute(buf, 40, 3)
if got := buf.GetLine(0); !strings.HasPrefix(got, "content") {
t.Fatalf("line 0 = %q, want content at column 0 (zero-width dyn spacer took flex share)", got)
}
spacer = 4
buf2 := NewBuffer(40, 3)
tmpl.Execute(buf2, 40, 3)
if got := buf2.GetLine(0); !strings.HasPrefix(got, "X content") {
t.Fatalf("line 0 = %q, want X then content at column 4 after widening", got)
}
}
// an explicit Text width — static or a dynamic binding — clips the content,
// matching container behaviour (declared size means what it says).
func TestTextExplicitWidthClipsContent(t *testing.T) {
w := int16(7)
tmpl := Build(HBox(
Text("████████████").Width(&w),
Text("|"),
))
buf := NewBuffer(20, 1)
tmpl.Execute(buf, 20, 1)
if got := buf.GetLine(0); got != "███████|" {
t.Fatalf("line = %q, want 7 blocks then pipe", got)
}
tmpl2 := Build(HBox(Text("abcdefgh").Width(4), Text("|")))
buf2 := NewBuffer(20, 1)
tmpl2.Execute(buf2, 20, 1)
if got := buf2.GetLine(0); got != "abcd|" {
t.Fatalf("static width line = %q, want abcd|", got)
}
}