File: tags_test.go

package info (click to toggle)
golang-github-johanneskaufmann-dom 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 176 kB
  • sloc: makefile: 3
file content (121 lines) | stat: -rw-r--r-- 2,159 bytes parent folder | download
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
package dom

import (
	"testing"

	"golang.org/x/net/html"
)

func TestNodeName(t *testing.T) {
	runs := []struct {
		name string
		node *html.Node
	}{
		{
			name: "",
			node: nil,
		},
		{
			name: "",
			node: &html.Node{
				Type: 10,
			},
		},
		{
			name: "#error",
			node: &html.Node{
				Type: html.ErrorNode,
			},
		},
		{
			name: "#text",
			node: &html.Node{
				Type: html.TextNode,
				Data: "some boring text",
			},
		},

		{
			name: "#document",
			node: &html.Node{
				Type: html.DocumentNode,
			},
		},
		{
			name: "#comment",
			node: &html.Node{
				Type: html.CommentNode,
			},
		},
		{
			name: "html",
			node: &html.Node{
				Type: html.DoctypeNode,
				// E.g. for `<!DOCTYPE html>` it would be "html"
				Data: "html",
			},
		},
		// - - - - - - - - - - //
		{
			name: "div",
			node: &html.Node{
				Type: html.ElementNode,
				Data: "div",
			},
		},
		{
			name: "a",
			node: &html.Node{
				Type: html.ElementNode,
				Data: "a",
			},
		},
	}
	for _, run := range runs {
		t.Run(run.name, func(t *testing.T) {
			output := NodeName(run.node)
			if output != run.name {
				t.Errorf("expected '%s' but got '%s'", run.name, output)
			}
		})
	}
}

func TestNameIsInlineNode(t *testing.T) {
	if out := NameIsInlineNode("strong"); out != true {
		t.Error("expected different output")
	}

	if out := NameIsInlineNode("div"); out != false {
		t.Error("expected different output")
	}
	if out := NameIsInlineNode("magic"); out != false {
		t.Error("expected different output")
	}
}

func TestNameIsBlockNode(t *testing.T) {
	if out := NameIsBlockNode("div"); out != true {
		t.Error("expected different output")
	}

	if out := NameIsBlockNode("strong"); out != false {
		t.Error("expected different output")
	}
	if out := NameIsBlockNode("magic"); out != false {
		t.Error("expected different output")
	}
}

func TestNameIsHeading(t *testing.T) {
	if out := NameIsHeading("h4"); out != true {
		t.Error("expected different output")
	}

	if out := NameIsHeading("strong"); out != false {
		t.Error("expected different output")
	}
	if out := NameIsHeading("magic"); out != false {
		t.Error("expected different output")
	}
}