OSDN Git Service

libgo: Update to weekly.2011-12-06.
[pf3gnuchains/gcc-fork.git] / libgo / go / html / render_test.go
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.
4
5 package html
6
7 import (
8         "bytes"
9         "testing"
10 )
11
12 func TestRenderer(t *testing.T) {
13         n := &Node{
14                 Type: ElementNode,
15                 Data: "html",
16                 Child: []*Node{
17                         {
18                                 Type: ElementNode,
19                                 Data: "head",
20                         },
21                         {
22                                 Type: ElementNode,
23                                 Data: "body",
24                                 Child: []*Node{
25                                         {
26                                                 Type: TextNode,
27                                                 Data: "0<1",
28                                         },
29                                         {
30                                                 Type: ElementNode,
31                                                 Data: "p",
32                                                 Attr: []Attribute{
33                                                         {
34                                                                 Key: "id",
35                                                                 Val: "A",
36                                                         },
37                                                         {
38                                                                 Key: "foo",
39                                                                 Val: `abc"def`,
40                                                         },
41                                                 },
42                                                 Child: []*Node{
43                                                         {
44                                                                 Type: TextNode,
45                                                                 Data: "2",
46                                                         },
47                                                         {
48                                                                 Type: ElementNode,
49                                                                 Data: "b",
50                                                                 Attr: []Attribute{
51                                                                         {
52                                                                                 Key: "empty",
53                                                                                 Val: "",
54                                                                         },
55                                                                 },
56                                                                 Child: []*Node{
57                                                                         {
58                                                                                 Type: TextNode,
59                                                                                 Data: "3",
60                                                                         },
61                                                                 },
62                                                         },
63                                                         {
64                                                                 Type: ElementNode,
65                                                                 Data: "i",
66                                                                 Attr: []Attribute{
67                                                                         {
68                                                                                 Key: "backslash",
69                                                                                 Val: `\`,
70                                                                         },
71                                                                 },
72                                                                 Child: []*Node{
73                                                                         {
74                                                                                 Type: TextNode,
75                                                                                 Data: "&4",
76                                                                         },
77                                                                 },
78                                                         },
79                                                 },
80                                         },
81                                         {
82                                                 Type: TextNode,
83                                                 Data: "5",
84                                         },
85                                         {
86                                                 Type: ElementNode,
87                                                 Data: "blockquote",
88                                         },
89                                         {
90                                                 Type: ElementNode,
91                                                 Data: "br",
92                                         },
93                                         {
94                                                 Type: TextNode,
95                                                 Data: "6",
96                                         },
97                                 },
98                         },
99                 },
100         }
101         want := `<html><head></head><body>0&lt;1<p id="A" foo="abc&quot;def">` +
102                 `2<b empty="">3</b><i backslash="\">&amp;4</i></p>` +
103                 `5<blockquote></blockquote><br/>6</body></html>`
104         b := new(bytes.Buffer)
105         if err := Render(b, n); err != nil {
106                 t.Fatal(err)
107         }
108         if got := b.String(); got != want {
109                 t.Errorf("got vs want:\n%s\n%s\n", got, want)
110         }
111 }