-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassList_test.go
More file actions
63 lines (50 loc) · 1.38 KB
/
classList_test.go
File metadata and controls
63 lines (50 loc) · 1.38 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
61
62
63
package GoHtml_test
import (
"fmt"
"testing"
GoHtml "github.com/udan-jayanith/GoHTML"
)
func TestClasses(t *testing.T) {
node := GoHtml.CreateNode("div")
node.SetAttribute("class", "div-container main")
classList := GoHtml.NewClassList()
classList.DecodeFrom(node)
if !classList.Contains("main") {
t.Fatal("")
return
}
classList.DeleteClass("main")
if classList.Contains("main") {
t.Fatal("")
return
}
classList.AppendClass("main-div")
if !classList.Contains("main-div") {
t.Fatal("")
return
}
classList.EncodeTo(node)
}
func ExampleClassList_Contains() {
//Creates a div that has classes video-container and main-contents
div := GoHtml.CreateNode("div")
div.SetAttribute("class", "video-container main-contents")
classList := GoHtml.NewClassList()
//Add the classes in the div to the class list
classList.DecodeFrom(div)
//Checks wether the following classes exists in the classList
fmt.Println(classList.Contains("container"))
fmt.Println(classList.Contains("video-container"))
//Output:
//false
//true
}
func ExampleClassList_Encode(){
classList := GoHtml.NewClassList()
//Add classes to the class list
classList.AppendClass("container")
classList.AppendClass("warper")
classList.AppendClass("main-content")
//This would output something like this "warper container main-content". Order of the output is not guaranteed.
fmt.Println(classList.Encode())
}