-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathforeach_switch_test.go
More file actions
41 lines (34 loc) · 767 Bytes
/
foreach_switch_test.go
File metadata and controls
41 lines (34 loc) · 767 Bytes
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
package glyph
import (
"strings"
"testing"
)
func TestSwitchInsideForEach(t *testing.T) {
type item struct {
Label string
Active bool
}
items := []item{
{Label: "alpha", Active: false},
{Label: "beta", Active: true},
{Label: "gamma", Active: false},
}
view := VBox(
ForEach(&items, func(it *item) any {
return If(&it.Active).
Then(Text(&it.Label).FG(Green)).
Else(Text(&it.Label).FG(BrightBlack))
}),
)
tmpl := Build(view)
buf := NewBuffer(40, 10)
tmpl.Execute(buf, 40, 10)
output := buf.String()
t.Logf("output:\n%s", output)
// all three labels must appear
for _, label := range []string{"alpha", "beta", "gamma"} {
if !strings.Contains(output, label) {
t.Errorf("label %q missing from output", label)
}
}
}