-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxhtml_test.go
143 lines (134 loc) · 3.14 KB
/
xhtml_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// This is Free Software covered by the terms of the MIT license.
// See LICENSE file for details.
// Copyright 2017 by Intevation GmbH
package main
import (
"bytes"
"testing"
)
func TestStandalone(t *testing.T) {
doc := document{
root: &node{
nodeType: heading1Node,
value: "Hello",
},
}
var buf bytes.Buffer
if err := exportXHTML(&doc, &buf, true); err != nil {
t.Fatalf("error: %v\n", err)
}
const want = xhtmlHeader + "<h1>Hello</h1>" + xhtmlFooter
if got := buf.String(); got != want {
t.Errorf("got '%s' want '%s'", got, want)
}
}
func TestElements(t *testing.T) {
cases := []testCase{{
have: text("Hello <&>"),
want: "Hello <&>",
}, {
have: &node{nodeType: horizontalLineNode},
want: "<hr/>",
}, {
have: &node{nodeType: lineBreakNode},
want: "<br/>",
}, {
have: nd(italicsNode, text("Hello")),
want: "<i>Hello</i>",
}, {
have: nd(boldNode, text("Hello")),
want: "<strong>Hello</strong>",
}, {
have: nd(strikeNode, text("Hello")),
want: "<del>Hello</del>",
}, {
have: nd(underlinedNode, text("Hello")),
want: "<em>Hello</em>",
}, {
have: nd(subscriptNode, text("Hello")),
want: "<sub>Hello</sub>",
}, {
have: nd(superscriptNode, text("Hello")),
want: "<sup>Hello</sup>",
}, {
have: nd(noWikiNode, text("Hello")),
want: "<pre><tt>Hello</tt></pre>",
}, {
have: nd(noWikiInlineNode, text("Hello")),
want: "<tt>Hello</tt>",
}, {
have: &node{nodeType: heading1Node},
want: "<h1></h1>",
}, {
have: &node{nodeType: heading2Node},
want: "<h2></h2>",
}, {
have: &node{nodeType: heading3Node},
want: "<h3></h3>",
}, {
have: &node{nodeType: heading4Node},
want: "<h4></h4>",
}, {
have: &node{nodeType: heading5Node},
want: "<h5></h5>",
}, {
have: &node{nodeType: heading6Node},
want: "<h6></h6>",
}, {
have: &node{nodeType: paragraphNode},
want: "<p></p>",
}, {
have: &node{
nodeType: linkNode,
value: "http://example.com",
children: []*node{text("Hello")},
},
want: `<a href="http://example.com">Hello</a>`,
}, {
have: &node{
nodeType: imageNode,
value: &image{
src: "http://example.com/image.png",
},
},
want: `<img src="http://example.com/image.png"></img>`,
}, {
have: &node{
nodeType: imageNode,
value: &image{
src: "http://example.com/image.png",
alt: "An image",
},
},
want: `<img src="http://example.com/image.png" alt="An image"></img>`,
}, {
have: nd(unorderedListNode,
nd(listItemNode, text("Hello")),
nd(listItemNode, text("World"))),
want: `<ul><li>Hello</li><li>World</li></ul>`,
}, {
have: nd(orderedListNode,
nd(listItemNode, text("Hello")),
nd(listItemNode, text("World"))),
want: `<ol><li>Hello</li><li>World</li></ol>`,
}, {
have: nd(tableNode,
nd(tableHeaderRowNode,
nd(tableHeaderCellNode, text("header1")),
nd(tableHeaderCellNode, text("header2"))),
nd(tableRowNode,
nd(tableCellNode, text("Hello")),
nd(tableCellNode, text("World")))),
want: "<table>" +
"<tr>" +
"<th>header1</th>" +
"<th>header2</th>" +
"</tr>" +
"<tr>" +
"<td>Hello</td>" +
"<td>World</td>" +
"</tr>" +
"</table>",
}}
runCases(cases, exportXHTML, t)
}