Debian Codegraph @

src/tests/table.rs

raw
1 use super::*;
2
3 #[test]
4 fn table() {
5 html_opts!(
6 [extension.table],
7 concat!("| a | b |\n", "|---|:-:|\n", "| c | d |\n"),
8 concat!(
9 "<table>\n",
10 "<thead>\n",
11 "<tr>\n",
12 "<th>a</th>\n",
13 "<th align=\"center\">b</th>\n",
14 "</tr>\n",
15 "</thead>\n",
16 "<tbody>\n",
17 "<tr>\n",
18 "<td>c</td>\n",
19 "<td align=\"center\">d</td>\n",
20 "</tr>\n",
21 "</tbody>\n",
22 "</table>\n"
23 ),
24 );
25 }
26
27 #[test]
28 fn table_regression() {
29 html_opts!(
30 [extension.table],
31 concat!("123\n", "456\n", "| a | b |\n", "| ---| --- |\n", "d | e\n"),
32 concat!(
33 "<p>123\n",
34 "456</p>\n",
35 "<table>\n",
36 "<thead>\n",
37 "<tr>\n",
38 "<th>a</th>\n",
39 "<th>b</th>\n",
40 "</tr>\n",
41 "</thead>\n",
42 "<tbody>\n",
43 "<tr>\n",
44 "<td>d</td>\n",
45 "<td>e</td>\n",
46 "</tr>\n",
47 "</tbody>\n",
48 "</table>\n"
49 ),
50 );
51 }
52
53 #[test]
54 fn table_misparse_1() {
55 html_opts!([extension.table], "a\n-b", "<p>a\n-b</p>\n");
56 }
57
58 #[test]
59 fn table_misparse_2() {
60 html_opts!([extension.table], "a\n-b\n-c", "<p>a\n-b\n-c</p>\n");
61 }
62
63 #[test]
64 fn nested_tables_1() {
65 html_opts!(
66 [extension.table],
67 concat!("- p\n", "\n", " |a|b|\n", " |-|-|\n", " |c|d|\n",),
68 concat!(
69 "<ul>\n",
70 "<li>\n",
71 "<p>p</p>\n",
72 "<table>\n",
73 "<thead>\n",
74 "<tr>\n",
75 "<th>a</th>\n",
76 "<th>b</th>\n",
77 "</tr>\n",
78 "</thead>\n",
79 "<tbody>\n",
80 "<tr>\n",
81 "<td>c</td>\n",
82 "<td>d</td>\n",
83 "</tr>\n",
84 "</tbody>\n",
85 "</table>\n",
86 "</li>\n",
87 "</ul>\n",
88 ),
89 );
90 }
91
92 #[test]
93 fn nested_tables_2() {
94 html_opts!(
95 [extension.table],
96 concat!("- |a|b|\n", " |-|-|\n", " |c|d|\n",),
97 concat!(
98 "<ul>\n",
99 "<li>\n",
100 "<table>\n",
101 "<thead>\n",
102 "<tr>\n",
103 "<th>a</th>\n",
104 "<th>b</th>\n",
105 "</tr>\n",
106 "</thead>\n",
107 "<tbody>\n",
108 "<tr>\n",
109 "<td>c</td>\n",
110 "<td>d</td>\n",
111 "</tr>\n",
112 "</tbody>\n",
113 "</table>\n",
114 "</li>\n",
115 "</ul>\n",
116 ),
117 );
118 }
119
120 #[test]
121 fn nested_tables_3() {
122 html_opts!(
123 [extension.table],
124 concat!("> |a|b|\n", "> |-|-|\n", "> |c|d|\n",),
125 concat!(
126 "<blockquote>\n",
127 "<table>\n",
128 "<thead>\n",
129 "<tr>\n",
130 "<th>a</th>\n",
131 "<th>b</th>\n",
132 "</tr>\n",
133 "</thead>\n",
134 "<tbody>\n",
135 "<tr>\n",
136 "<td>c</td>\n",
137 "<td>d</td>\n",
138 "</tr>\n",
139 "</tbody>\n",
140 "</table>\n",
141 "</blockquote>\n",
142 ),
143 );
144 }
145
146 #[test]
147 fn sourcepos_with_preceding_para_no_spaces() {
148 assert_ast_match!(
149 [extension.table],
150 "123\n"
151 "456\n"
152 "| a | b |\n"
153 "| - | - |\n"
154 "| c | d |\n"
155 ,
156 (document (1:1-5:9) [
157 (paragraph (1:1-2:3) [
158 (text (1:1-1:3) "123")
159 (softbreak (1:4-1:4))
160 (text (2:1-2:3) "456")
161 ])
162 (table (3:1-5:9) [
163 (table_row (3:1-3:9) [
164 (table_cell (3:2-3:4) [
165 (text (3:3-3:3) "a")
166 ])
167 (table_cell (3:6-3:8) [
168 (text (3:7-3:7) "b")
169 ])
170 ])
171 (table_row (5:1-5:9) [
172 (table_cell (5:2-5:4) [
173 (text (5:3-5:3) "c")
174 ])
175 (table_cell (5:6-5:8) [
176 (text (5:7-5:7) "d")
177 ])
178 ])
179 ])
180 ])
181 );
182 }
183
184 #[test]
185 fn sourcepos_with_preceding_para_spaces_before_table() {
186 assert_ast_match!(
187 [extension.table],
188 "123\n"
189 "456\n"
190 " | a | b |\n"
191 " | - | - |\n"
192 " | c | d |\n"
193 ,
194 (document (1:1-5:10) [
195 (paragraph (1:1-2:3) [
196 (text (1:1-1:3) "123")
197 (softbreak (1:4-1:4))
198 (text (2:1-2:3) "456")
199 ])
200 (table (3:2-5:10) [
201 (table_row (3:2-3:10) [
202 (table_cell (3:3-3:5) [
203 (text (3:4-3:4) "a")
204 ])
205 (table_cell (3:7-3:9) [
206 (text (3:8-3:8) "b")
207 ])
208 ])
209 (table_row (5:2-5:10) [
210 (table_cell (5:3-5:5) [
211 (text (5:4-5:4) "c")
212 ])
213 (table_cell (5:7-5:9) [
214 (text (5:8-5:8) "d")
215 ])
216 ])
217 ])
218 ])
219 );
220 }
221
222 #[test]
223 fn sourcepos_with_preceding_para_spaces_before_para() {
224 assert_ast_match!(
225 [extension.table],
226 " 123\n"
227 " 456\n"
228 "| a | b |\n"
229 "| - | - |\n"
230 "| c | d |\n"
231 ,
232 (document (1:1-5:9) [
233 (paragraph (1:2-2:5) [
234 (text (1:2-1:4) "123")
235 (softbreak (1:5-1:5))
236 (text (2:3-2:5) "456")
237 ])
238 (table (3:1-5:9) [
239 (table_row (3:1-3:9) [
240 (table_cell (3:2-3:4) [
241 (text (3:3-3:3) "a")
242 ])
243 (table_cell (3:6-3:8) [
244 (text (3:7-3:7) "b")
245 ])
246 ])
247 (table_row (5:1-5:9) [
248 (table_cell (5:2-5:4) [
249 (text (5:3-5:3) "c")
250 ])
251 (table_cell (5:6-5:8) [
252 (text (5:7-5:7) "d")
253 ])
254 ])
255 ])
256 ])
257 );
258 }
259
260 #[test]
261 fn sourcepos_with_preceding_para_spaces_before_both() {
262 assert_ast_match!(
263 [extension.table],
264 " 123\n"
265 " 456\n"
266 " | a | b |\n"
267 " | - | - |\n"
268 " | c | d |\n"
269 ,
270 (document (1:1-5:10) [
271 (paragraph (1:2-2:5) [
272 (text (1:2-1:4) "123")
273 (softbreak (1:5-1:5))
274 (text (2:3-2:5) "456")
275 ])
276 (table (3:2-5:10) [
277 (table_row (3:2-3:10) [
278 (table_cell (3:3-3:5) [
279 (text (3:4-3:4) "a")
280 ])
281 (table_cell (3:7-3:9) [
282 (text (3:8-3:8) "b")
283 ])
284 ])
285 (table_row (5:2-5:10) [
286 (table_cell (5:3-5:5) [
287 (text (5:4-5:4) "c")
288 ])
289 (table_cell (5:7-5:9) [
290 (text (5:8-5:8) "d")
291 ])
292 ])
293 ])
294 ])
295 );
296 }
297
298 #[test]
299 fn table_crlf() {
300 assert_ast_match!(
301 [extension.table],
302 "| a | b |\r\n"
303 "| - | - |\r\n"
304 "| c | d |\r\n"
305 ,
306 (document (1:1-3:9) [
307 (table (1:1-3:9) [
308 (table_row (1:1-1:9) [
309 (table_cell (1:2-1:4) [
310 (text (1:3-1:3) "a")
311 ])
312 (table_cell (1:6-1:8) [
313 (text (1:7-1:7) "b")
314 ])
315 ])
316 (table_row (3:1-3:9) [
317 (table_cell (3:2-3:4) [
318 (text (3:3-3:3) "c")
319 ])
320 (table_cell (3:6-3:8) [
321 (text (3:7-3:7) "d")
322 ])
323 ])
324 ])
325 ])
326 );
327 }
328
329 #[test]
330 fn table_cr() {
331 assert_ast_match!(
332 [extension.table],
333 "| a | b |\r"
334 "| - | - |\r"
335 "| c | d |\r"
336 ,
337 (document (1:1-3:9) [
338 (table (1:1-3:9) [
339 (table_row (1:1-1:9) [
340 (table_cell (1:2-1:4) [
341 (text (1:3-1:3) "a")
342 ])
343 (table_cell (1:6-1:8) [
344 (text (1:7-1:7) "b")
345 ])
346 ])
347 (table_row (3:1-3:9) [
348 (table_cell (3:2-3:4) [
349 (text (3:3-3:3) "c")
350 ])
351 (table_cell (3:6-3:8) [
352 (text (3:7-3:7) "d")
353 ])
354 ])
355 ])
356 ])
357 );
358 }
359
360 #[test]
361 fn table_no_body_no_eol_at_eof() {
362 assert_ast_match!(
363 [extension.table],
364 "| a |\n"
365 "| - |"
366 ,
367 (document (1:1-2:5) [
368 (table (1:1-2:5) [
369 (table_row (1:1-1:5) [
370 (table_cell (1:2-1:4) [
371 (text (1:3-1:3) "a")
372 ])
373 ])
374 ])
375 ])
376 );
377 }
378
379 #[test]
380 fn table_with_trailing_para() {
381 assert_ast_match!(
382 [extension.table],
383 "| a |\n"
384 "| - |\n"
385 "\n"
386 "ok"
387 ,
388 (document (1:1-4:2) [
389 (table (1:1-2:5) [
390 (table_row (1:1-1:5) [
391 (table_cell (1:2-1:4) [
392 (text (1:3-1:3) "a")
393 ])
394 ])
395 ])
396 (paragraph (4:1-4:2) [
397 (text (4:1-4:2) "ok")
398 ])
399 ])
400 );
401 }
402
403 #[test]
404 fn table_with_trailing_para_and_leading_whitespace() {
405 assert_ast_match!(
406 [extension.table],
407 " | a |\n"
408 " | - |\n"
409 "\n"
410 " ok"
411 ,
412 (document (1:1-4:3) [
413 (table (1:3-2:7) [
414 (table_row (1:3-1:8) [
415 (table_cell (1:4-1:7) [
416 (text (1:5-1:5) "a")
417 ])
418 ])
419 ])
420 (paragraph (4:2-4:3) [
421 (text (4:2-4:3) "ok")
422 ])
423 ])
424 );
425 }
426
427 #[test]
428 fn table_missing_cell_sourcepos() {
429 assert_ast_match!(
430 [extension.table],
431 "|a|b|\n"
432 "|-|-|\n"
433 "|c|\n"
434 ,
435 (document (1:1-3:3) [
436 (table (1:1-3:3) [
437 (table_row (1:1-1:5) [
438 (table_cell (1:2-1:2) [
439 (text (1:2-1:2) "a")
440 ])
441 (table_cell (1:4-1:4) [
442 (text (1:4-1:4) "b")
443 ])
444 ])
445 (table_row (3:1-3:3) [
446 (table_cell (3:2-3:2) [
447 (text (3:2-3:2) "c")
448 ])
449 (table_cell (3:3-3:3)
450 )
451 ])
452 ])
453 ])
454 );
455 }
456
457 #[test]
458 fn table_missing_cell_with_text_sourcepos() {
459 assert_ast_match!(
460 [extension.table],
461 "|a|b|\n"
462 "|-|-|\n"
463 "|c|d\n"
464 ,
465 (document (1:1-3:4) [
466 (table (1:1-3:4) [
467 (table_row (1:1-1:5) [
468 (table_cell (1:2-1:2) [
469 (text (1:2-1:2) "a")
470 ])
471 (table_cell (1:4-1:4) [
472 (text (1:4-1:4) "b")
473 ])
474 ])
475 (table_row (3:1-3:4) [
476 (table_cell (3:2-3:2) [
477 (text (3:2-3:2) "c")
478 ])
479 (table_cell (3:4-3:4) [
480 (text (3:4-3:4) "d")
481 ])
482 ])
483 ])
484 ])
485 );
486 }
487
488 #[test]
489 fn table_missing_cells_sourcepos() {
490 assert_ast_match!(
491 [extension.table],
492 "|a|b|c|\n"
493 "|-|-|-|\n"
494 "|d|\n"
495 ,
496 (document (1:1-3:3) [
497 (table (1:1-3:3) [
498 (table_row (1:1-1:7) [
499 (table_cell (1:2-1:2) [
500 (text (1:2-1:2) "a")
501 ])
502 (table_cell (1:4-1:4) [
503 (text (1:4-1:4) "b")
504 ])
505 (table_cell (1:6-1:6) [
506 (text (1:6-1:6) "c")
507 ])
508 ])
509 (table_row (3:1-3:3) [
510 (table_cell (3:2-3:2) [
511 (text (3:2-3:2) "d")
512 ])
513 (table_cell (3:3-3:3)
514 )
515 (table_cell (3:3-3:3)
516 )
517 ])
518 ])
519 ])
520 );
521 }