File: tag_element_test.go

package info (click to toggle)
golang-github-yosssi-gohtml 0.0~git20180130.97fbf36-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 140 kB
  • sloc: makefile: 2
file content (33 lines) | stat: -rw-r--r-- 894 bytes parent folder | download | duplicates (4)
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
package gohtml

import (
	"bytes"
	"testing"
)

func TestTagElementWrite(t *testing.T) {
	tagElem := &tagElement{tagName: "body", startTagRaw: "<body>", endTagRaw: "</body>"}
	child := &tagElement{tagName: "input", startTagRaw: "<input>"}
	grandChild := &textElement{text: "Test text"}
	child.appendChild(grandChild)
	tagElem.appendChild(child)
	bf := &bytes.Buffer{}
	tagElem.write(bf, 0)
	actual := bf.String()
	expected := `<body>
  <input>
  Test text
</body>`
	if actual != expected {
		t.Errorf("Invalid result. [expected: %s][actual: %s]", expected, actual)
	}
}

func TestTagElementAppendChild(t *testing.T) {
	tagElem := &tagElement{}
	child := &textElement{text: "TestText"}
	tagElem.appendChild(child)
	if len(tagElem.children) != 1 || tagElem.children[0] != child {
		t.Errorf("tagElement.children is invalid. [expected: %+v][actual: %+v]", []element{child}, tagElem.children)
	}
}