Repository navigation
Expand file tree
/
Copy pathdebug_test.go
More file actions
115 lines (110 loc) · 3.42 KB
/
Copy pathdebug_test.go
File metadata and controls
115 lines (110 loc) · 3.42 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
// Copyright (c) Liam Stanley <liam@liam.sh>. All rights reserved. Use of
// this source code is governed by the MIT license that can be found in
// the LICENSE file.
package bloom
import (
"strings"
"testing"
"bloomfx.dev/bloom/fx"
"charm.land/lipgloss/v2"
)
func TestDebug(t *testing.T) {
t.Parallel()
panes := Column(
Row(
Fixed(10, Box(lipgloss.NewStyle().Border(lipgloss.RoundedBorder()), Text("Inbox"))).ID("sidebar").Collapsible(1),
Fill(View(benchView{"reader"})).ID("reader").Min(12),
),
Text("ready").Truncate(),
)
for _, tt := range []struct {
name string
c Child
w, h int
want string
}{
{"panes", panes, 30, 5, `
Column 0,0 30x5
├─ Row 0,0 30x3
│ ├─ Fixed(10) id="sidebar" 0,0 10x3 collapsible=1
│ │ └─ Box 0,0 10x3
│ │ └─ Text "Inbox" 1,1 8x1
│ └─ Fill id="reader" 10,0 20x3 min=12
│ └─ View(bloom.benchView) 10,0 20x3
└─ Text "ready" 0,3 30x1 truncate
`},
{"collapsed", panes, 15, 5, `
Column 0,0 15x5
├─ Row 0,0 15x1
│ ├─ Fixed(10) id="sidebar" hidden collapsible=1
│ │ └─ Box hidden
│ │ └─ Text "Inbox" hidden
│ └─ Fill id="reader" 0,0 15x1 min=12
│ └─ View(bloom.benchView) 0,0 15x1
└─ Text "ready" 0,1 15x1 truncate
`},
{"overlay", Overlay(
Column(
Fixed(1, Scroll(Column(Text("a").ID("pane1"), Text("b"), Text("c")), 1)),
Marquee("scrolling", 0),
Text("in").ID("in").Focusable(),
Transition(0.5, Text("fading in over the frame beneath"), fx.Fade{}),
),
Layer(Text("drop")).AnchorTo("in", Bottom).Modal(),
Layer(Text("gone")).AnchorTo("missing", Top),
Layer(Text("toast")).ID("a\nb").Anchor(End, Start).Offset(-1, 0).Margin(1).Size(6, 1),
), 20, 5, `
Overlay 0,0 20x5
├─ Column 0,0 20x5
│ ├─ Fixed(1) 0,0 20x1
│ │ └─ Scroll 0,0 20x1 offset=1
│ │ └─ Column 0,-1 20x3 visible=0,0 20x1
│ │ ├─ Text "a" id="pane1" 0,-1 20x1 offscreen
│ │ ├─ Text "b" 0,0 20x1
│ │ └─ Text "c" 0,1 20x1 offscreen
│ ├─ bloom.MarqueeNode 0,1 20x1
│ │ └─ Text "scrolling" 0,1 20x1
│ ├─ Text "in" id="in" 0,2 20x1 focusable
│ └─ Transition 0,3 20x2 t=0.50 effects=fx.Fade
│ └─ Text "fading in over the fram…" 0,3 20x2
├─ Layer 0,3 4x1 anchorTo="in"/bottom modal scope
│ └─ Text "drop" 0,3 4x1
├─ Layer hidden anchorTo="missing"/top
│ └─ Text "gone" hidden
└─ Layer id="a\nb" 12,1 6x1 anchor=end,start offset=-1,0 margin=1 size=6x1
└─ Text "toast" 12,1 6x1
`},
{"duplicate", Row(
Fill(Text("a")).ID("pane"),
Fill(Text("b")).ID("pane"),
Fill(Text("c")).ID("other"),
), 9, 1, `
Row 0,0 9x1
├─ Fill id="pane" 0,0 3x1
│ └─ Text "a" 0,0 3x1
├─ Fill id="pane" duplicate 3,0 3x1
│ └─ Text "b" 3,0 3x1
└─ Fill id="other" 6,0 3x1
└─ Text "c" 6,0 3x1
`},
{"nil", nil, 10, 1, "\n"},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got, want := Debug(tt.w, tt.h, tt.c), strings.TrimPrefix(tt.want, "\n"); got != want {
t.Fatalf("got:\n%s\nwant:\n%s", got, want)
}
})
}
}
// TestDuplicateIDsPanicInTests draws two nodes with the same ID, which
// panics in a test binary.
func TestDuplicateIDsPanicInTests(t *testing.T) {
t.Parallel()
defer func() {
if recover() == nil {
t.Fatal("two nodes with the same ID did not panic")
}
}()
New().Render(10, 1, Row(Text("a").ID("x"), Text("b").ID("x")))
}