1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 func TestRenderer(t *testing.T) {
94 // Build a tree out of those nodes, based on a textual representation.
95 // Only the ".\t"s are significant. The trailing HTML-like text is
96 // just commentary. The "0:" prefixes are for easy cross-reference with
98 treeAsText := [...]string{
103 4: `. . <p id="A" foo="abc"def">`,
105 6: `. . . <b empty="">`,
107 8: `. . . <i backslash="\">`,
108 9: `. . . . "&4"`,
110 11: `. . <blockquote>`,
114 if len(nodes) != len(treeAsText) {
115 t.Fatal("len(nodes) != len(treeAsText)")
118 for i, line := range treeAsText {
121 // Strip a leading ".\t".
128 t.Fatal("multiple root nodes")
132 stack[level-1].AppendChild(n)
134 for i := level + 1; i < len(stack); i++ {
138 // At each stage of tree construction, we check all nodes for consistency.
139 for j, m := range nodes {
140 if err := checkNodeConsistency(m); err != nil {
141 t.Fatalf("i=%d, j=%d: %v", i, j, err)
146 want := `<html><head></head><body>0<1<p id="A" foo="abc"def">` +
147 `2<b empty="">3</b><i backslash="\">&4</i></p>` +
148 `5<blockquote></blockquote><br/>6</body></html>`
149 b := new(bytes.Buffer)
150 if err := Render(b, nodes[0]); err != nil {
153 if got := b.String(); got != want {
154 t.Errorf("got vs want:\n%s\n%s\n", got, want)