This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate_test.go
99 lines (89 loc) · 1.87 KB
/
update_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
package gas
import (
"testing"
)
func TestUpdateChildes(t *testing.T) {
tree := NE(
&E{Tag: "main", RC: GetEmptyRenderCore()},
NE(
&E{Tag: "div"},
"wow",
),
NE(
&E{Tag: "h1", Attrs: func() Map { return Map{"id": "wow"} }},
"Title",
),
NE(
&E{Tag: "p"},
"Lorem ipsum dolore",
" ",
NE(
&E{Tag: "i", Attrs: func() Map { return Map{"id": "lol", "class": "some"} }},
"opsum",
),
NE(
&E{Tag: "b"},
"fote",
NE(
&E{Tag: "i"},
"wate",
),
NE(
&E{HTML: func() string { return "<h2>some</h2>" }},
),
),
),
)
tree.UpdateChildes()
isChildValid := func(i interface{}) {
e, ok := i.(*E)
if !ok {
t.Errorf("invalid first child type: %T", tree.Childes[0])
}
if len(e.Tag) == 0 || len(e.UUID) == 0 || e.RC == nil || e.Parent == nil {
t.Errorf("invalid child *Element: %v", e)
}
}
isChildValid(tree.Childes[0])
isChildValid(tree.Childes[1])
isChildValid(tree.Childes[2])
isChildValid(tree.Childes[2].(*E).Childes[2])
isChildValid(tree.Childes[2].(*E).Childes[3])
isChildValid(tree.Childes[2].(*E).Childes[3].(*E).Childes[1])
isChildValid(tree.Childes[2].(*E).Childes[3].(*E).Childes[2])
if tree.Childes[2].(*E).Childes[3].(*E).Childes[2].(*E).RHTML == "" {
t.Error("invalid html directive")
}
}
func TestUpdateElementChildes(t *testing.T) {
var nodes []*RenderTask
root := &exampleRoot{
msg: "no",
counter: 5,
}
c := &C{
RC: &RenderCore{
BE: emptyBackEnd{
logger: func(newNodes []*RenderTask) {
nodes = append(nodes, newNodes...)
},
},
},
NotPointer: true,
Root: root,
}
root.c = c
f := func(i int) {
if len(nodes) != i {
t.Errorf("not enough render nodes, want: %d, but got: %d, nodes: %v", i, len(nodes), nodes)
return
}
nodes = []*RenderTask{}
}
root.c.Update()
f(1)
root.counter = 6
root.msg = "wow"
root.c.Update()
f(2)
}