aboutsummaryrefslogtreecommitdiffstats
path: root/renderer/src/html/tests.rs
blob: a4ec633106018cd686ac2934999b122bc60dba7c (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
use pretty_assertions::assert_eq;

use rst_parser::parse;

use crate::html::render_html;

fn check_renders_to(rst: &str, expected: &str) {
	println!("Rendering:\n{}\n---", rst);
	let doc = parse(rst).expect("Cannot parse");
	let mut result_data: Vec<u8> = vec![];
	render_html(&doc, &mut result_data, false).expect("Render error");
	let result = String::from_utf8(result_data).expect("Could not decode");
	assert_eq!(result.as_str().trim(), expected);
	println!("{}", expected);
}

#[test]
fn simple_string() {
	check_renders_to(
		"Simple String",
		"<p>Simple String</p>",
	);
}

#[test]
fn simple_string_with_markup() {
	check_renders_to(
		"Simple String with *emph* and **strong**",
		"<p>Simple String with <em>emph</em> and <strong>strong</strong></p>",
	);
}

#[test]
fn inline_literal() {
	check_renders_to(
		"Simple String with an even simpler ``inline literal``",
		"<p>Simple String with an even simpler <code>inline literal</code></p>",
	);
}

/*
#[test]
fn test_reference_anonymous() {
	check_renders_to("\
A simple `anonymous reference`__

__ http://www.test.com/test_url
", "\
<p>A simple <a href=\"http://www.test.com/test_url\">anonymous reference</a></p>\
");
}
*/

#[test]
fn two_paragraphs() {
	check_renders_to(
		"One paragraph.\n\nTwo paragraphs.",
		"<p>One paragraph.</p>\n<p>Two paragraphs.</p>",
	);
}

#[test]
fn named_reference() {
	check_renders_to("\
A simple `named reference`_ with stuff in between the
reference and the target.

.. _`named reference`: http://www.test.com/test_url
", "\
<p>A simple <a href=\"http://www.test.com/test_url\">named reference</a> with stuff in between the \
reference and the target.</p>\
");
}

#[test]
fn standalone_hyperlinks() {
	check_renders_to("\
Some http://url and a not_url_scheme:foo that is not supposed to be an url.
", "\
<p>Some <a href=\"http://url/\">http://url</a> and a not_url_scheme:foo that is not supposed to be an url.</p>\
");
}

#[test]
fn substitution() {
	check_renders_to("\
A |subst|.

.. |subst| replace:: text substitution
", "<p>A text substitution.</p>");
}

#[test]
fn not_substitution_literal() {
	check_renders_to("\
hello ``foo.map(|world| world + 42)``

.. |world| replace:: something different

.. code::

   foo.map(|world| world + 42)

::

    hay! |x|
", "<p>hello <code>foo.map(|world| world + 42)</code></p>
<pre><code>foo.map(|world| world + 42)\n</code></pre>
<pre>hay! |x|\n</pre>");
}

/*
#[test]
fn test_section_hierarchy() {
	check_renders_to("\
+++++
Title
+++++

Subtitle
========

Some stuff

Section
-------

Some more stuff

Another Section
...............

And even more stuff
", "\
<p>Some stuff</p>
<section id=\"section\">
<h1>Section</h1>
<p>Some more stuff</p>
<section id=\"another-section\">
<h2>Another Section</h2>
<p>And even more stuff</p>
</section>
</section>\
");
}

#[test]
fn test_docinfo_title() {
	check_renders_to("\
+++++
Title
+++++

:author: me

Some stuff
", "\
<main id=\"title\">
<h1 class=\"title\">Title</h1>
<dl class=\"docinfo simple\">
<dt class=\"author\">Author</dt>
<dd class=\"author\"><p>me</p></dd>
</dl>
<p>Some stuff</p>
</main>\
");
}
*/

#[test]
fn section_hierarchy() {
	check_renders_to("\
+++++
Title
+++++

Not A Subtitle
==============

Some stuff

Section
-------

Some more stuff

Another Section
...............

And even more stuff
", "\
<section id=\"title\">
<h1>Title</h1>
<section id=\"not-a-subtitle\">
<h2>Not A Subtitle</h2>
<p>Some stuff</p>
<section id=\"section\">
<h3>Section</h3>
<p>Some more stuff</p>
<section id=\"another-section\">
<h4>Another Section</h4>
<p>And even more stuff</p>
</section>
</section>
</section>
</section>\
");
}

#[test]
fn many_sections() {
	check_renders_to("\
+++++++++
heading 1
+++++++++

heading 2
=========

First stuff

heading 2a
----------

First detail

heading 3
=========

Second stuff

heading 3a
----------

Second detail
", "\
<section id=\"heading-1\">
<h1>heading 1</h1>
<section id=\"heading-2\">
<h2>heading 2</h2>
<p>First stuff</p>
<section id=\"heading-2a\">
<h3>heading 2a</h3>
<p>First detail</p>
</section>
</section>
<section id=\"heading-3\">
<h2>heading 3</h2>
<p>Second stuff</p>
<section id=\"heading-3a\">
<h3>heading 3a</h3>
<p>Second detail</p>
</section>
</section>
</section>\
");
}

#[test]
fn bullet_list() {
	check_renders_to("\
* bullet
* list
", "\
<ul>
<li><p>bullet</p></li>
<li><p>list</p></li>
</ul>\
");
}

/*
#[test]
fn test_table() {
	check_renders_to("\
.. table::
   :align: right

   +-----+-----+
   |  1  |  2  |
   +-----+-----+
   |  3  |  4  |
   +-----+-----+
", "\
<table class=\"align-right\">
<colgroup>
<col style=\"width: 50%%\" />
<col style=\"width: 50%%\" />
</colgroup>
<tbody>
<tr><td><p>1</p></td>
<td><p>2</p></td>
</tr>
<tr><td><p>3</p></td>
<td><p>4</p></td>
</tr>
</tbody>
</table>\
");
}
*/

#[test]
fn code() {
	check_renders_to("\
.. code:: python

   def foo():
       print('Hi!')
   
       # comment
", "\
<pre><code class=\"language-python\">def foo():
    print('Hi!')

    # comment
</code></pre>\
");
}

#[test]
fn raw_html() {
	check_renders_to("\
.. raw:: html

   hello <span>world</span>
   <p>paragraph

   paragraph</p>

after

.. raw:: something_else

   into a black hole this goes
", "\
hello <span>world</span>
<p>paragraph

paragraph</p>

<p>after</p>\
");
}

#[test]
fn comments() {
	check_renders_to("\
.. Run-in
   comment

..

    block-like

    with blank lines
", "\
<!--Run-in
comment
-->
<!--block-like

with blank lines
-->\
");
}

/*
#[test]
fn test_field_list() {
	check_renders_to("\
Not a docinfo.

:This: .. _target:

       is
:a:
:simple:
:field: list
", "\
<p>Not a docinfo.</p>
<dl class=\"field-list\">
<dt>This</dt>
<dd><p id=\"target\">is</p>
</dd>
<dt>a</dt>
<dd><p></p></dd>
<dt>simple</dt>
<dd><p></p></dd>
<dt>field</dt>
<dd><p>list</p>
</dd>
</dl>\
");
}
*/

/*
#[test]
fn test_field_list_long() {
	check_renders_to("\
Not a docinfo.

:This is: a
:simple field list with loooong field: names
", "\
<p>Not a docinfo.</p>
<dl class=\"field-list\">
<dt>This is</dt>
<dd><p>a</p>
</dd>
<dt>simple field list with loooong field</dt>
<dd><p>names</p>
</dd>
</dl>\
");
}
*/