-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path_view_splitter_test.v
More file actions
129 lines (120 loc) · 3.12 KB
/
_view_splitter_test.v
File metadata and controls
129 lines (120 loc) · 3.12 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
117
118
119
120
121
122
123
124
125
126
127
128
129
module gui
fn noop_splitter_change(_ f32, _ SplitterCollapsed, mut _e Event, mut _w Window) {}
fn test_splitter_state_normalize() {
state := splitter_state_normalize(SplitterState{
ratio: 1.5
collapsed: .first
})
assert state.ratio == 1
assert state.collapsed == .first
}
fn test_splitter_effective_collapsed() {
core := SplitterCore{
id: 'splitter-collapse'
on_change: noop_splitter_change
first: SplitterPaneCore{
collapsible: false
}
second: SplitterPaneCore{
collapsible: true
}
}
assert splitter_effective_collapsed(&core, .first) == .none
assert splitter_effective_collapsed(&core, .second) == .second
assert splitter_effective_collapsed(&core, .none) == .none
}
fn test_splitter_toggle_target() {
core := SplitterCore{
id: 'splitter-toggle'
on_change: noop_splitter_change
first: SplitterPaneCore{
collapsible: false
}
second: SplitterPaneCore{
collapsible: true
}
}
assert splitter_toggle_target(&core, .none) == .second
}
fn test_splitter_toggle_target_prefers_current_collapsed() {
core := SplitterCore{
id: 'splitter-toggle-current'
on_change: noop_splitter_change
first: SplitterPaneCore{
collapsible: true
}
second: SplitterPaneCore{
collapsible: true
}
}
assert splitter_toggle_target(&core, .second) == .second
assert splitter_toggle_target(&core, .first) == .first
assert splitter_toggle_target(&core, .none) == .first
}
fn test_splitter_clamp_ratio_respects_constraints() {
core := SplitterCore{
id: 'splitter-clamp'
on_change: noop_splitter_change
first: SplitterPaneCore{
min_size: 100
}
second: SplitterPaneCore{
min_size: 200
}
}
available := f32(600)
min_ratio := splitter_clamp_ratio(&core, available, 0.0)
max_ratio := splitter_clamp_ratio(&core, available, 1.0)
assert f32_are_close(min_ratio, 100 / 600.0)
assert f32_are_close(max_ratio, 400 / 600.0)
}
fn test_splitter_compute_collapsed_first() {
core := SplitterCore{
id: 'splitter-compute'
on_change: noop_splitter_change
collapsed: .first
handle_size: 8
first: SplitterPaneCore{
collapsible: true
collapsed_size: 20
min_size: 10
}
second: SplitterPaneCore{
min_size: 100
}
}
computed := splitter_compute(&core, 300)
assert computed.collapsed == .first
assert computed.handle_main == core.handle_size
assert computed.first_main >= 10
assert computed.second_main >= 100
}
fn test_splitter_collapsed_second_rebalances_after_max_clamp() {
core := SplitterCore{
id: 'splitter-collapsed-second'
on_change: noop_splitter_change
first: SplitterPaneCore{
max_size: 300
}
second: SplitterPaneCore{
max_size: 100
collapsible: true
collapsed_size: 0
}
}
first, second := splitter_collapsed_second(&core, 500)
assert f32_are_close(second, 100)
assert f32_are_close(first + second, 500)
}
fn test_splitter_builds_view() {
_ := splitter(
id: 'splitter-build'
on_change: noop_splitter_change
first: SplitterPaneCfg{
content: [text(text: 'A')]
}
second: SplitterPaneCfg{
content: [text(text: 'B')]
}
)
}