-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-list_test.go
More file actions
60 lines (51 loc) · 1.06 KB
/
node-list_test.go
File metadata and controls
60 lines (51 loc) · 1.06 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
package GoHtml_test
import (
"fmt"
"os"
"testing"
GoHtml "github.com/udan-jayanith/GoHTML"
)
func TestIterNodeList1(t *testing.T) {
file, err := os.Open("./test-files/3.html")
if err != nil {
t.Fatal(err)
return
}
defer file.Close()
node, err := GoHtml.Decode(file)
if err != nil {
t.Fatal(err)
return
}
list := GoHtml.NewNodeList()
traverser := GoHtml.NewTraverser(node)
traverser.Walkthrough(func(node *GoHtml.Node) GoHtml.TraverseCondition {
list.Append(node)
return GoHtml.ContinueWalkthrough
})
iterator := list.IterNodeList()
for node := range iterator{
node.RemoveNode()
}
}
func TestIterNodeList2(t *testing.T){
nodeList := GoHtml.NewNodeList()
iter := nodeList.IterNodeList()
for node := range iter{
t.Log(node)
}
}
func ExampleNodeList(){
nodeList := GoHtml.NewNodeList()
nodeList.Append(GoHtml.CreateNode("br"))
nodeList.Append(GoHtml.CreateNode("hr"))
nodeList.Append(GoHtml.CreateNode("div"))
iter := nodeList.IterNodeList()
for node := range iter{
fmt.Println(node.GetTagName())
}
//Output:
//br
//hr
//div
}