예제 #1
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>")
}
예제 #2
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>")
}
예제 #3
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>")
}