-
Notifications
You must be signed in to change notification settings - Fork 1
/
measure_cache_test.go
170 lines (132 loc) · 4.18 KB
/
measure_cache_test.go
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
package flex
import (
"testing"
"github.com/stretchr/testify/assert"
)
func measureMax(node *Node, width float32, widthMode MeasureMode, height float32, heightMode MeasureMode) Size {
measureCount := node.Context.(int)
measureCount++
node.Context = measureCount
if widthMode == MeasureModeUndefined {
width = 10
}
if heightMode == MeasureModeUndefined {
height = 10
}
return Size{
Width: width,
Height: height,
}
}
func measureMin(node *Node, width float32, widthMode MeasureMode, height float32, heightMode MeasureMode) Size {
measureCount := node.Context.(int)
measureCount++
node.Context = measureCount
if widthMode == MeasureModeUndefined || (widthMode == MeasureModeAtMost && width > 10) {
width = 10
}
if heightMode == MeasureModeUndefined || (heightMode == MeasureModeAtMost && height > 10) {
height = 10
}
return Size{
Width: width,
Height: height,
}
}
func measure8449(node *Node, width float32, widthMode MeasureMode, height float32, heightMode MeasureMode) Size {
measureCount, ok := node.Context.(int)
if ok {
measureCount++
node.Context = measureCount
}
return Size{
Width: 84,
Height: 49,
}
}
func TestMeasure_once_single_flexible_child(t *testing.T) {
root := NewNode()
root.StyleSetFlexDirection(FlexDirectionRow)
root.StyleSetAlignItems(AlignFlexStart)
root.StyleSetWidth(100)
root.StyleSetHeight(100)
rootChild0 := NewNode()
measureCount := 0
rootChild0.Context = measureCount
rootChild0.SetMeasureFunc(measureMax)
rootChild0.StyleSetFlexGrow(1)
root.InsertChild(rootChild0, 0)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
measureCount = rootChild0.Context.(int)
assert.Equal(t, 1, measureCount)
}
func TestRemeasure_with_same_exact_width_larger_than_needed_height(t *testing.T) {
root := NewNode()
rootChild0 := NewNode()
measureCount := 0
rootChild0.Context = measureCount
rootChild0.SetMeasureFunc(measureMin)
root.InsertChild(rootChild0, 0)
CalculateLayout(root, 100, 100, DirectionLTR)
CalculateLayout(root, 100, 50, DirectionLTR)
measureCount = rootChild0.Context.(int)
assert.Equal(t, 1, measureCount)
}
func TestRemeasure_with_same_atmost_width_larger_than_needed_height(t *testing.T) {
root := NewNode()
root.StyleSetAlignItems(AlignFlexStart)
rootChild0 := NewNode()
measureCount := 0
rootChild0.Context = measureCount
rootChild0.SetMeasureFunc(measureMin)
root.InsertChild(rootChild0, 0)
CalculateLayout(root, 100, 100, DirectionLTR)
CalculateLayout(root, 100, 50, DirectionLTR)
measureCount = rootChild0.Context.(int)
assert.Equal(t, 1, measureCount)
}
func TestRemeasure_with_computed_width_larger_than_needed_height(t *testing.T) {
root := NewNode()
root.StyleSetAlignItems(AlignFlexStart)
rootChild0 := NewNode()
measureCount := 0
rootChild0.Context = measureCount
rootChild0.SetMeasureFunc(measureMin)
root.InsertChild(rootChild0, 0)
CalculateLayout(root, 100, 100, DirectionLTR)
root.StyleSetAlignItems(AlignStretch)
CalculateLayout(root, 10, 50, DirectionLTR)
measureCount = rootChild0.Context.(int)
assert.Equal(t, 1, measureCount)
}
func TestRemeasure_with_atmost_computed_width_undefined_height(t *testing.T) {
root := NewNode()
root.StyleSetAlignItems(AlignFlexStart)
rootChild0 := NewNode()
measureCount := 0
rootChild0.Context = measureCount
rootChild0.SetMeasureFunc(measureMin)
root.InsertChild(rootChild0, 0)
CalculateLayout(root, 100, Undefined, DirectionLTR)
CalculateLayout(root, 10, Undefined, DirectionLTR)
measureCount = rootChild0.Context.(int)
assert.Equal(t, 1, measureCount)
}
func TestRemeasure_with_already_measured_value_smaller_but_still_float_equal(t *testing.T) {
measureCount := 0
root := NewNode()
root.StyleSetWidth(288)
root.StyleSetHeight(288)
root.StyleSetFlexDirection(FlexDirectionRow)
rootChild0 := NewNode()
rootChild0.StyleSetPadding(EdgeAll, 2.88)
rootChild0.StyleSetFlexDirection(FlexDirectionRow)
root.InsertChild(rootChild0, 0)
rootChild0Child0 := NewNode()
rootChild0Child0.Context = measureCount
rootChild0Child0.SetMeasureFunc(measure8449)
rootChild0.InsertChild(rootChild0Child0, 0)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
measureCount = rootChild0Child0.Context.(int)
assert.Equal(t, 1, measureCount)
}