1 extern crate html2runes;
2
3 use html2runes::markdown::*;
4
5 #[test]
plaintext()6 fn plaintext() {
7 let result = convert_string("My little car.");
8 assert_eq!("My little car.", result);
9 }
10
11 #[test]
newlines_are_ignored()12 fn newlines_are_ignored() {
13 let result = convert_string(
14 "My
15 little
16 car.",
17 );
18 assert_eq!("My little car.", result);
19 }
20
21 #[test]
lines_with_empty_spaces_are_killed()22 fn lines_with_empty_spaces_are_killed() {
23 let result = convert_string("<p>a b c</p>\n <p>d e f</p>");
24 assert_eq!("a b c\n\nd e f", result);
25 }
26
27 #[test]
ending_space_is_trimmed()28 fn ending_space_is_trimmed() {
29 let result = convert_string("a b c <br> \n <br>d e f");
30 assert_eq!("a b c\nd e f", result);
31 }
32
33 #[test]
bold()34 fn bold() {
35 let result = convert_string("My <b>little</b> car.");
36 assert_eq!("My **little** car.", result);
37
38 let result = convert_string("My <strong>little</strong> car.");
39 assert_eq!("My **little** car.", result);
40 }
41
42 #[test]
emphasize()43 fn emphasize() {
44 let result = convert_string("My <i>little</i> car.");
45 assert_eq!("My *little* car.", result);
46
47 let result = convert_string("My <em>little</em> car.");
48 assert_eq!("My *little* car.", result);
49 }
50
51 #[test]
paragraph()52 fn paragraph() {
53 let result = convert_string("<p>A piece of text<br></p><p>Another piece</p>");
54 assert_eq!("A piece of text\n\nAnother piece", result);
55
56 let result = convert_string(
57 "<p>A piece of text</p>
58 <p>Another piece</p>",
59 );
60 assert_eq!("A piece of text\n\nAnother piece", result);
61
62 let result = convert_string("<p>A piece of text<p>Another piece");
63 assert_eq!("A piece of text\n\nAnother piece", result);
64
65 let result = convert_string("<div>A piece of text</div><p>Another piece");
66 assert_eq!("A piece of text\n\nAnother piece", result);
67 }
68
69 #[test]
newline()70 fn newline() {
71 let result = convert_string("one<br>two<br/>three<br></br>four");
72 assert_eq!("one\ntwo\nthree\nfour", result);
73
74 let result = convert_string("one<br><br><br>two");
75 assert_eq!("one\ntwo", result);
76
77 let result = convert_string("<br>none");
78 assert_eq!("none", result);
79 }
80
81 #[test]
blockquote()82 fn blockquote() {
83 let result = convert_string("<blockquote>just a quote</blockquote>");
84 assert_eq!("> just a quote\n", result);
85
86 let result = convert_string(
87 "<blockquote>a nested<blockquote>quote should give \
88 double</blockquote>lines</blockquote>",
89 );
90 assert_eq!(
91 "> a nested
92 >> quote should give double
93 > lines\n",
94 result
95 );
96
97 let result = convert_string(
98 "<p>And he said:</p><blockquote>Quote me</blockquote>and all was \
99 good.",
100 );
101 assert_eq!(
102 "And he said:
103 > Quote me
104 and all was good.",
105 result
106 );
107
108 let result = convert_string(
109 "And he said:<blockquote>A long long piece of text<br>which you \
110 can find in the quote</blockquote>and all was good.",
111 );
112 assert_eq!(
113 "And he said:
114 > A long long piece of text
115 > which you can find in the quote
116 and all was good.",
117 result
118 );
119 }
120
121 #[test]
link()122 fn link() {
123 let result = convert_string("here is a <a href=\"http://google.com\">link</a> to google");
124 assert_eq!("here is a [link](http://google.com) to google", result);
125 }
126
127 #[test]
image()128 fn image() {
129 let result = convert_string("here is an <img alt=\"image\" src=\"bla.png\">");
130 assert_eq!("here is an ![image](bla.png)", result);
131 }
132
133 #[test]
ignoring_styles()134 fn ignoring_styles() {
135 let result = convert_string("should ignore style tag<style>I AM STYLE</style>");
136 assert_eq!("should ignore style tag", result);
137 }
138
139 #[test]
ignoring_scripts()140 fn ignoring_scripts() {
141 let result = convert_string("should ignore script tag<script>I AM SCRIPT</script>");
142 assert_eq!("should ignore script tag", result);
143 }
144
145 #[test]
ignoring_head()146 fn ignoring_head() {
147 let result = convert_string(
148 "<html><head><title>I AM HEAD</title></head><body>should ignore \
149 head tag</body></html>",
150 );
151 assert_eq!("should ignore head tag", result);
152 }
153
154 #[test]
unordered_list()155 fn unordered_list() {
156 let expected = "Here's a list:
157
158 * first
159 * second
160
161 Wasn't it good?";
162 let result = convert_string(
163 "Here's a list: <ul><li>first</li><li>second</li></ul> Wasn't it \
164 good?",
165 );
166 assert_eq!(expected, result);
167
168 let result = convert_string(
169 "<p>Here's a list:</p> <ul><li>first</li><li>second</li></ul> \
170 <p>Wasn't it good?</p>",
171 );
172 assert_eq!(expected, result);
173 }
174
175 #[test]
unordered_more_complex_list()176 fn unordered_more_complex_list() {
177 let expected = "Here's a list:
178
179 * A paragraph
180 with two lines.
181
182 With a blank line in between.
183 * second item
184 with three
185 lines
186 * as well as
187
188 * a nested
189 list
190 * of two
191
192 and the nested list ended
193
194 Wasn't it good?";
195 let result = convert_string(
196 "Here's a list: <ul><li><p>A paragraph<br>with two lines.</p>
197 <p>With a blank line in between.</p></li>
198 <li><br>second item<br>with three\n<br><br>lines</li>
199 <li>as well as
200 <ul>
201 <li>a nested<br>list</li>
202 <li><p>of two</p></li></ul>
203 and the nested list ended</li>
204 </ul> Wasn't it good?",
205 );
206 assert_eq!(expected, result);
207 }
208
209 #[test]
ordered_list()210 fn ordered_list() {
211 let expected = "Here's a list:
212
213 1. first
214 2. second
215
216 Wasn't it good?";
217 let result = convert_string(
218 "Here's a list: <ol><li>first</li><li>second</li></ol> Wasn't it \
219 good?",
220 );
221 assert_eq!(expected, result);
222
223 let result = convert_string(
224 "<p>Here's a list:</p> <ol><li>first</li><li>second</li></ol> \
225 <p>Wasn't it good?</p>",
226 );
227 assert_eq!(expected, result);
228 }
229
230 #[test]
ordered_more_complex_list()231 fn ordered_more_complex_list() {
232 let expected = "Here's a list:
233
234 1. A paragraph
235 with two lines.
236
237 With a blank line in between.
238 2. second item
239 with three
240 lines
241 3. as well as
242
243 1. a nested
244 list
245 2. of two
246
247 and the nested list ended
248
249 Wasn't it good?";
250 let result = convert_string(
251 "Here's a list: <ol><li><p>A paragraph<br>with two lines.</p>
252 <p>With a blank line in between.</p></li>
253 <li><br>second item<br>with three\n<br><br>lines</li>
254 <li>as well as
255 <ol>
256 <li>a nested<br>list</li>
257 <li><p>of two</p></li></ol>
258 and the nested list ended</li>
259 </ol> Wasn't it good?",
260 );
261 assert_eq!(expected, result);
262 }
263
264 #[test]
ordered_and_unordered_mixed()265 fn ordered_and_unordered_mixed() {
266 let expected = "Here's a list:
267
268 1. A paragraph
269 with two lines.
270
271 With a blank line in between.
272 2. as well as
273
274 * a nested
275 list
276
277 1. Even more nested list
278 2. Inside of that
279
280 * of two
281
282 and the nested list ended
283 3. But then a third item followed
284
285 Wasn't it good?";
286 let result = convert_string(
287 "Here's a list:
288 <ol>
289 <li><p>A paragraph<br>with two lines.</p>
290 <p>With a blank line in between.</p></li>
291 <li>as well as
292 <ul>
293 <li>a nested<br>list
294 <ol>
295 <li>Even more nested list</li>
296 <li>Inside of that</li>
297 </ol>
298 </li>
299 <li><p>of two</p></li>
300 </ul>
301 and the nested list ended</li>
302 <li>But then a third item followed</li>
303 </ol>
304 Wasn't it good?",
305 );
306 assert_eq!(expected, result);
307 }
308