File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,16 @@ func (n *Node) InnerText() string {
142
142
return b .String ()
143
143
}
144
144
145
+ // ChildNodes returns all the child nodes of the current node,
146
+ // including text, comments, and char data.
147
+ func (n * Node ) ChildNodes () []* Node {
148
+ var list []* Node
149
+ for child := n .FirstChild ; child != nil ; child = child .NextSibling {
150
+ list = append (list , child )
151
+ }
152
+ return list
153
+ }
154
+
145
155
func (n * Node ) sanitizedData (preserveSpaces bool ) string {
146
156
if preserveSpaces {
147
157
return n .Data
Original file line number Diff line number Diff line change @@ -117,6 +117,20 @@ func verifyNodePointers(t *testing.T, n *Node) {
117
117
testTrue (t , parent == nil || parent .LastChild == cur )
118
118
}
119
119
120
+ func TestChildNodes (t * testing.T ) {
121
+ t .Run ("Has 3 children" , func (t * testing.T ) {
122
+ node := & Node {Type : ElementNode }
123
+
124
+ AddChild (node , & Node {Type : CommentNode })
125
+ AddChild (node , & Node {Type : ElementNode })
126
+ AddChild (node , & Node {Type : TextNode })
127
+
128
+ children := node .ChildNodes ()
129
+
130
+ testTrue (t , len (children ) == 3 )
131
+ })
132
+ }
133
+
120
134
func TestAddAttr (t * testing.T ) {
121
135
for _ , test := range []struct {
122
136
name string
You can’t perform that action at this time.
0 commit comments