-
Notifications
You must be signed in to change notification settings - Fork 1
/
dirty_marking_test.go
132 lines (100 loc) · 3.44 KB
/
dirty_marking_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
package flex
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDirty_propagation(t *testing.T) {
root := NewNode()
root.StyleSetAlignItems(AlignFlexStart)
root.StyleSetWidth(100)
root.StyleSetHeight(100)
rootChild0 := NewNode()
rootChild0.StyleSetWidth(50)
rootChild0.StyleSetHeight(20)
root.InsertChild(rootChild0, 0)
rootChild1 := NewNode()
rootChild1.StyleSetWidth(50)
rootChild1.StyleSetHeight(20)
root.InsertChild(rootChild1, 1)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
rootChild0.StyleSetWidth(20)
assert.True(t, rootChild0.IsDirty)
assert.False(t, rootChild1.IsDirty)
assert.True(t, root.IsDirty)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
assert.False(t, rootChild0.IsDirty)
assert.False(t, rootChild1.IsDirty)
assert.False(t, root.IsDirty)
}
func TestDirty_propagation_only_if_prop_changed(t *testing.T) {
root := NewNode()
root.StyleSetAlignItems(AlignFlexStart)
root.StyleSetWidth(100)
root.StyleSetHeight(100)
rootChild0 := NewNode()
rootChild0.StyleSetWidth(50)
rootChild0.StyleSetHeight(20)
root.InsertChild(rootChild0, 0)
rootChild1 := NewNode()
rootChild1.StyleSetWidth(50)
rootChild1.StyleSetHeight(20)
root.InsertChild(rootChild1, 1)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
rootChild0.StyleSetWidth(50)
assert.False(t, rootChild0.IsDirty)
assert.False(t, rootChild1.IsDirty)
assert.False(t, root.IsDirty)
}
func TestDirty_mark_all_children_as_dirty_when_display_changes(t *testing.T) {
root := NewNode()
root.StyleSetFlexDirection(FlexDirectionRow)
root.StyleSetHeight(100)
child0 := NewNode()
child0.StyleSetFlexGrow(1)
child1 := NewNode()
child1.StyleSetFlexGrow(1)
child1Child0 := NewNode()
child1Child0Child0 := NewNode()
child1Child0Child0.StyleSetWidth(8)
child1Child0Child0.StyleSetHeight(16)
child1Child0.InsertChild(child1Child0Child0, 0)
child1.InsertChild(child1Child0, 0)
root.InsertChild(child0, 0)
root.InsertChild(child1, 0)
child0.StyleSetDisplay(DisplayFlex)
child1.StyleSetDisplay(DisplayNone)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
assertFloatEqual(t, 0, child1Child0Child0.LayoutGetWidth())
assertFloatEqual(t, 0, child1Child0Child0.LayoutGetHeight())
child0.StyleSetDisplay(DisplayNone)
child1.StyleSetDisplay(DisplayFlex)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
assertFloatEqual(t, 8, child1Child0Child0.LayoutGetWidth())
assertFloatEqual(t, 16, child1Child0Child0.LayoutGetHeight())
child0.StyleSetDisplay(DisplayFlex)
child1.StyleSetDisplay(DisplayNone)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
assertFloatEqual(t, 0, child1Child0Child0.LayoutGetWidth())
assertFloatEqual(t, 0, child1Child0Child0.LayoutGetHeight())
child0.StyleSetDisplay(DisplayNone)
child1.StyleSetDisplay(DisplayFlex)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
assertFloatEqual(t, 8, child1Child0Child0.LayoutGetWidth())
assertFloatEqual(t, 16, child1Child0Child0.LayoutGetHeight())
}
func TestDirty_node_only_if_children_are_actually_removed(t *testing.T) {
root := NewNode()
root.StyleSetAlignItems(AlignFlexStart)
root.StyleSetWidth(50)
root.StyleSetHeight(50)
child0 := NewNode()
child0.StyleSetWidth(50)
child0.StyleSetHeight(25)
root.InsertChild(child0, 0)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
child1 := NewNode()
root.RemoveChild(child1)
assert.False(t, root.IsDirty)
root.RemoveChild(child0)
assert.True(t, root.IsDirty)
}