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>") }
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>") }
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>") }
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>") }
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>") }
func TestRemoveChildren(t *testing.T) { node := h5.Anchor("", "foo") RemoveChildren()(node) assertEqual(t, h5.NewTree(node).String(), "<a></a>") }