]>
Commit | Line | Data |
---|---|---|
48663c56 XL |
1 | // Tests for HTML spec. |
2 | ||
3 | extern crate pulldown_cmark; | |
4 | ||
416331ca | 5 | use pulldown_cmark::{html, Options, Parser}; |
48663c56 XL |
6 | |
7 | #[test] | |
8 | fn html_test_1() { | |
9 | let original = r##"Little header | |
10 | ||
11 | <script type="text/js"> | |
12 | function some_func() { | |
13 | console.log("teeeest"); | |
14 | } | |
15 | ||
16 | ||
17 | function another_func() { | |
18 | console.log("fooooo"); | |
19 | } | |
20 | </script>"##; | |
21 | let expected = r##"<p>Little header</p> | |
22 | <script type="text/js"> | |
23 | function some_func() { | |
24 | console.log("teeeest"); | |
25 | } | |
26 | ||
27 | ||
28 | function another_func() { | |
29 | console.log("fooooo"); | |
30 | } | |
31 | </script>"##; | |
32 | ||
33 | let mut s = String::new(); | |
34 | html::push_html(&mut s, Parser::new(&original)); | |
35 | assert_eq!(expected, s); | |
36 | } | |
37 | ||
38 | #[test] | |
39 | fn html_test_2() { | |
40 | let original = r##"Little header | |
41 | ||
42 | <script | |
43 | type="text/js"> | |
44 | function some_func() { | |
45 | console.log("teeeest"); | |
46 | } | |
47 | ||
48 | ||
49 | function another_func() { | |
50 | console.log("fooooo"); | |
51 | } | |
52 | </script>"##; | |
53 | let expected = r##"<p>Little header</p> | |
54 | <script | |
55 | type="text/js"> | |
56 | function some_func() { | |
57 | console.log("teeeest"); | |
58 | } | |
59 | ||
60 | ||
61 | function another_func() { | |
62 | console.log("fooooo"); | |
63 | } | |
64 | </script>"##; | |
65 | ||
66 | let mut s = String::new(); | |
67 | html::push_html(&mut s, Parser::new(&original)); | |
68 | assert_eq!(expected, s); | |
69 | } | |
70 | ||
71 | #[test] | |
72 | fn html_test_3() { | |
73 | let original = r##"Little header | |
74 | ||
75 | <? | |
76 | <div></div> | |
77 | <p>Useless</p> | |
78 | ?>"##; | |
79 | let expected = r##"<p>Little header</p> | |
80 | <? | |
81 | <div></div> | |
82 | <p>Useless</p> | |
83 | ?>"##; | |
84 | ||
85 | let mut s = String::new(); | |
86 | html::push_html(&mut s, Parser::new(&original)); | |
87 | assert_eq!(expected, s); | |
88 | } | |
89 | ||
90 | #[test] | |
91 | fn html_test_4() { | |
92 | let original = r##"Little header | |
93 | ||
94 | <!-- | |
95 | <div></div> | |
96 | <p>Useless</p> | |
97 | -->"##; | |
98 | let expected = r##"<p>Little header</p> | |
99 | <!-- | |
100 | <div></div> | |
101 | <p>Useless</p> | |
102 | -->"##; | |
103 | ||
104 | let mut s = String::new(); | |
105 | html::push_html(&mut s, Parser::new(&original)); | |
106 | assert_eq!(expected, s); | |
107 | } | |
108 | ||
109 | #[test] | |
110 | fn html_test_5() { | |
111 | let original = r##"Little header | |
112 | ||
113 | <![CDATA[ | |
114 | <div></div> | |
115 | <p>Useless</p> | |
116 | ]]>"##; | |
117 | let expected = r##"<p>Little header</p> | |
118 | <![CDATA[ | |
119 | <div></div> | |
120 | <p>Useless</p> | |
121 | ]]>"##; | |
122 | ||
123 | let mut s = String::new(); | |
124 | html::push_html(&mut s, Parser::new(&original)); | |
125 | assert_eq!(expected, s); | |
126 | } | |
127 | ||
128 | #[test] | |
129 | fn html_test_6() { | |
130 | let original = r##"Little header | |
131 | ||
132 | <!X | |
133 | Some things are here... | |
134 | >"##; | |
135 | let expected = r##"<p>Little header</p> | |
136 | <!X | |
137 | Some things are here... | |
138 | >"##; | |
139 | ||
140 | let mut s = String::new(); | |
141 | html::push_html(&mut s, Parser::new(&original)); | |
142 | assert_eq!(expected, s); | |
143 | } | |
144 | ||
145 | #[test] | |
146 | fn html_test_7() { | |
147 | let original = r##"Little header | |
148 | ----------- | |
149 | ||
150 | <script> | |
151 | function some_func() { | |
152 | console.log("teeeest"); | |
153 | } | |
154 | ||
155 | ||
156 | function another_func() { | |
157 | console.log("fooooo"); | |
158 | } | |
159 | </script>"##; | |
160 | let expected = r##"<h2>Little header</h2> | |
161 | <script> | |
162 | function some_func() { | |
163 | console.log("teeeest"); | |
164 | } | |
165 | ||
166 | ||
167 | function another_func() { | |
168 | console.log("fooooo"); | |
169 | } | |
170 | </script>"##; | |
171 | ||
172 | let mut s = String::new(); | |
173 | html::push_html(&mut s, Parser::new(&original)); | |
174 | assert_eq!(expected, s); | |
175 | } | |
176 | ||
177 | #[test] | |
178 | fn html_test_8() { | |
179 | let original = "A | B\n---|---\nfoo | bar"; | |
180 | let expected = r##"<table><thead><tr><th>A</th><th>B</th></tr></thead><tbody> | |
181 | <tr><td>foo</td><td>bar</td></tr> | |
182 | </tbody></table> | |
183 | "##; | |
184 | ||
185 | let mut s = String::new(); | |
186 | let mut opts = Options::empty(); | |
187 | opts.insert(Options::ENABLE_TABLES); | |
188 | html::push_html(&mut s, Parser::new_ext(&original, opts)); | |
189 | assert_eq!(expected, s); | |
190 | } | |
191 | ||
192 | #[test] | |
193 | fn html_test_9() { | |
194 | let original = "---"; | |
195 | let expected = "<hr />\n"; | |
196 | ||
197 | let mut s = String::new(); | |
198 | html::push_html(&mut s, Parser::new(&original)); | |
199 | assert_eq!(expected, s); | |
200 | } | |
201 | ||
202 | #[test] | |
203 | fn html_test_10() { | |
204 | let original = "* * *"; | |
205 | let expected = "<hr />\n"; | |
206 | ||
207 | let mut s = String::new(); | |
208 | html::push_html(&mut s, Parser::new(&original)); | |
209 | assert_eq!(expected, s); | |
210 | } | |
211 | ||
212 | // TODO: add broken link callback feature | |
213 | /* | |
214 | #[test] | |
215 | fn html_test_broken_callback() { | |
216 | let original = r##"[foo], | |
217 | [bar], | |
218 | [baz], | |
219 | ||
220 | [baz]: https://example.org | |
221 | "##; | |
222 | ||
223 | let expected = r##"<p><a href="https://replaced.example.org" title="some title">foo</a>, | |
224 | [bar], | |
225 | <a href="https://example.org">baz</a>,</p> | |
226 | "##; | |
227 | ||
228 | use pulldown_cmark::{Options, Parser, html}; | |
229 | ||
230 | let mut s = String::new(); | |
231 | ||
232 | let callback = |reference: &str, _normalized: &str| -> Option<(String, String)> { | |
233 | if reference == "foo" || reference == "baz" { | |
234 | Some(("https://replaced.example.org".into(), "some title".into())) | |
235 | } else { | |
236 | None | |
237 | } | |
238 | }; | |
239 | ||
240 | let p = Parser::new_with_broken_link_callback(&original, Options::empty(), Some(&callback)); | |
241 | html::push_html(&mut s, p); | |
242 | ||
243 | assert_eq!(expected, s); | |
244 | } | |
245 | */ |