Debian Codegraph @

src/tests/pathological.rs

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #![cfg(not(target_arch = "riscv64"))]
2
3 use super::*;
4 use ntest::timeout;
5
6 // input: python3 -c 'n = 50000; print("*a_ " * n)'
7 #[test]
8 #[timeout(4000)]
9 fn pathological_emphases() {
10 let n = 50_000;
11 let input = "*a_ ".repeat(n);
12 let mut exp = format!("<p>{}", input);
13 // Right-most space is trimmed in output.
14 exp.pop();
15 exp += "</p>\n";
16
17 html(&input, &exp);
18 }
19
20 // input: python3 -c 'n = 10000; print("|" + "x|" * n + "\n|" + "-|" * n)'
21 #[test]
22 #[timeout(4000)]
23 fn pathological_table_columns_1() {
24 let n = 100_000;
25 let input = format!("{}{}{}{}", "|", "x|".repeat(n), "\n|", "-|".repeat(n));
26 let exp = format!("<p>{}</p>\n", input);
27
28 html_opts!([extension.table], &input, &exp);
29 }
30
31 // input: python3 -c 'n = 70000; print("|" + "x|" * n + "\n|" + "-|" * n + "\n" + "a\n" * n)'
32 #[test]
33 #[timeout(4000)]
34 fn pathological_table_columns_2() {
35 let n = 100_000;
36 let input = format!(
37 "{}{}{}{}{}{}",
38 "|",
39 "x|".repeat(n),
40 "\n|",
41 "-|".repeat(n),
42 "\n",
43 "a\n".repeat(n)
44 );
45
46 let extension = parser::options::Extension {
47 table: true,
48 ..Default::default()
49 };
50
51 // Not interested in the actual html, just that we don't timeout
52 markdown_to_html(
53 &input,
54 &Options {
55 extension,
56 ..Default::default()
57 },
58 );
59 }
60
61 // input: python3 -c 'n = 10000; print("[^1]:" * n + "\n" * n)'
62 #[test]
63 #[timeout(4000)]
64 fn pathological_footnotes() {
65 let n = 10_000;
66 let input = format!("{}{}", "[^1]:".repeat(n), "\n".repeat(n));
67 let exp = "";
68
69 html_opts!([extension.footnotes], &input, exp);
70 }
71
72 #[test]
73 fn pathological_recursion() {
74 let n = 5_000;
75 let input = format!("{}{}", "*a **a ".repeat(n), " a** a*".repeat(n));
76 let exp = format!(
77 "<p>{}{}</p>\n",
78 "<em>a <strong>a ".repeat(n),
79 " a</strong> a</em>".repeat(n)
80 );
81
82 // The footnote code happened to be the cause of the pathological recursion, but it didn't
83 // actually depend on any footnotes being present; it was the search that caused it.
84 html_opts!([extension.footnotes], &input, &exp);
85 }
86
87 #[test]
88 fn pathological_recursion_inline_footnotes() {
89 let n = 5_000;
90 let input = format!("{}{}", "^[a ".repeat(n), " b]".repeat(n));
91 let exp = format!(
92 "{}{}{}{}",
93 concat!(
94 "<p><sup class=\"footnote-ref\"><a href=\"#fn-__inline_1\" id=\"fnref-__inline_1\" data-footnote-ref>1</a></sup></p>\n",
95 "<section class=\"footnotes\" data-footnotes>\n<ol>\n",
96 "<li id=\"fn-__inline_1\">\n<p>a <sup class=\"footnote-ref\"><a href=\"#fn-__inline_2\" id=\"fnref-__inline_2\" data-footnote-ref>5</a></sup> b <a href=\"#fnref-__inline_1\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1\" aria-label=\"Back to reference 1\">↩</a></p>\n</li>\n",
97 "<li id=\"fn-__inline_5\">\n<p>a ",
98 ),
99 "^[a ".repeat(4995),
100 " b]".repeat(4995),
101 concat!(
102 " b <a href=\"#fnref-__inline_5\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"2\" aria-label=\"Back to reference 2\">↩</a></p>\n</li>\n",
103 "<li id=\"fn-__inline_4\">\n<p>a <sup class=\"footnote-ref\"><a href=\"#fn-__inline_5\" id=\"fnref-__inline_5\" data-footnote-ref>2</a></sup> b <a href=\"#fnref-__inline_4\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"3\" aria-label=\"Back to reference 3\">↩</a></p>\n</li>\n",
104 "<li id=\"fn-__inline_3\">\n<p>a <sup class=\"footnote-ref\"><a href=\"#fn-__inline_4\" id=\"fnref-__inline_4\" data-footnote-ref>3</a></sup> b <a href=\"#fnref-__inline_3\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"4\" aria-label=\"Back to reference 4\">↩</a></p>\n</li>\n",
105 "<li id=\"fn-__inline_2\">\n<p>a <sup class=\"footnote-ref\"><a href=\"#fn-__inline_3\" id=\"fnref-__inline_3\" data-footnote-ref>4</a></sup> b <a href=\"#fnref-__inline_2\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"5\" aria-label=\"Back to reference 5\">↩</a></p>\n</li>\n",
106 "</ol>\n</section>\n"
107 )
108 );
109
110 html_opts!(
111 [extension.footnotes, extension.inline_footnotes],
112 &input,
113 &exp,
114 no_roundtrip
115 );
116 }