Exemplo n.º 1
0
func TestReplaceChildren(t *testing.T) {
	node := h5.Anchor("", "foo")
	assertEqual(t, h5.NewTree(node).String(), "<a>foo</a>")
	child := h5.Text("baz ")
	child2 := h5.Text("quux")
	ReplaceChildren(child, child2)(node)
	assertEqual(t, h5.NewTree(node).String(), "<a>baz quux</a>")
}
Exemplo n.º 2
0
func TestAppendChildren(t *testing.T) {
	node := h5.Anchor("", "")
	child := h5.Text("foo ")
	child2 := h5.Text("bar")
	AppendChildren(child, child2)(node)
	assertEqual(t, h5.NewTree(node).String(), "<a>foo bar</a>")
}
Exemplo n.º 3
0
func TestCopyAnd(t *testing.T) {
	defer func() {
		if err := recover(); err != nil {
			t.Errorf("TestCopyAnd paniced %s", err)
		}
	}()
	node := h5.Div("", nil, h5.Div("", nil, h5.Text("foo")))
	assertEqual(t, h5.NewTree(node).String(),
		"<div><div>foo</div></div>")
	CopyAnd(
		AppendChildren(h5.Text("bar")),
		ReplaceChildren(h5.Text("baz")),
	)(node.FirstChild)
	assertEqual(t, h5.NewTree(node).String(),
		"<div><div>foobar</div><div>baz</div></div>")
}
Exemplo n.º 4
0
func TestReplace(t *testing.T) {
	defer func() {
		if err := recover(); err != nil {
			t.Error("TestReplace paniced")
		}
	}()
	node := h5.Div("", nil, h5.Div("", nil, h5.Text("foo")))
	replacement := h5.Div("", nil, h5.Text("bar"))
	Replace(replacement)(node.FirstChild)
	assertEqual(t, h5.NewTree(node).String(),
		"<div><div>bar</div></div>")
}
Exemplo n.º 5
0
func TestReplaceSplice(t *testing.T) {
	defer func() {
		if err := recover(); err != nil {
			t.Error("TestReplaceSplice paniced")
		}
	}()
	node := h5.Div("foo", nil,
		h5.Text("foo"),
		h5.Element("span", nil, h5.Text("bar")),
	)
	node2 := h5.Element("span", nil, h5.Text("foo"))
	Replace(node2)(node.FirstChild)
	assertEqual(t, h5.NewTree(node).String(),
		"<div id=\"foo\"><span>foo</span><span>bar</span></div>")
}
Exemplo n.º 6
0
func TestRemoveChildren(t *testing.T) {
	node := h5.Anchor("", "foo")
	RemoveChildren()(node)
	assertEqual(t, h5.NewTree(node).String(), "<a></a>")
}