Debian Codegraph @

tests/testsuite/markdown.rs

raw
1 //! Tests for special markdown rendering.
2
3 use crate::prelude::*;
4 use snapbox::file;
5
6 // Checks custom header id and classes.
7 #[test]
8 fn custom_header_attributes() {
9 BookTest::from_dir("markdown/custom_header_attributes")
10 .check_main_file("book/custom_header_attributes.html", str![[r##"
11 <h1 id="attrs"><a class="header" href="#attrs">Heading Attributes</a></h1>
12 <h2 class="class1 class2" id="heading-with-classes"><a class="header" href="#heading-with-classes">Heading with classes</a></h2>
13 <h2 id="both" class="class1 class2"><a class="header" href="#both">Heading with id and classes</a></h2>
14 <h2 myattr="" otherattr="value" id="myh3" class="myclass1 myclass2"><a class="header" href="#myh3">Heading with attribute</a></h2>
15 "##]]);
16 }
17
18 // Test for a variety of footnote renderings.
19 #[test]
20 fn footnotes() {
21 BookTest::from_dir("markdown/footnotes")
22 .run("build", |cmd| {
23 cmd.expect_stderr(str![[r#"
24 INFO Book building has started
25 INFO Running the html backend
26 WARN footnote `multiple-definitions` in footnotes.md defined multiple times - not updating to new definition
27 WARN footnote `unused` in `footnotes.md` is defined but not referenced
28 INFO HTML book written to `[ROOT]/book`
29
30 "#]]);
31 })
32 .check_main_file(
33 "book/footnotes.html",
34 file!["markdown/footnotes/expected/footnotes.html"],
35 );
36 }
37
38 // Basic table test.
39 #[test]
40 fn tables() {
41 BookTest::from_dir("markdown/tables").check_main_file(
42 "book/tables.html",
43 str![[r##"
44 <h1 id="tables"><a class="header" href="#tables">Tables</a></h1>
45 <div class="table-wrapper">
46 <table>
47 <thead>
48 <tr><th>foo</th><th>bar</th></tr>
49 </thead>
50 <tbody>
51 <tr><td>baz</td><td>bim</td></tr>
52 <tr><td>Backslash in code</td><td><code>/</code></td></tr>
53 <tr><td>Double back in code</td><td><code>//</code></td></tr>
54 <tr><td>Pipe in code</td><td><code>|</code></td></tr>
55 <tr><td>Pipe in code2</td><td><code>test | inside</code></td></tr>
56 </tbody>
57 </table>
58 </div>
59 <div class="table-wrapper">
60 <table>
61 <thead>
62 <tr><th>Neither</th><th style="text-align: left">Left</th><th style="text-align: center">Center</th><th style="text-align: right">Right</th></tr>
63 </thead>
64 <tbody>
65 <tr><td>one</td><td style="text-align: left">two</td><td style="text-align: center">three</td><td style="text-align: right">four</td></tr>
66 </tbody>
67 </table>
68 </div>
69 "##]],
70 );
71 }
72
73 // Strikethrough test.
74 #[test]
75 fn strikethrough() {
76 BookTest::from_dir("markdown/strikethrough").check_main_file(
77 "book/strikethrough.html",
78 str![[r##"
79 <h1 id="strikethrough"><a class="header" href="#strikethrough">Strikethrough</a></h1>
80 <p><del>strikethrough example</del></p>
81 "##]],
82 );
83 }
84
85 // Tasklist test.
86 #[test]
87 fn tasklists() {
88 BookTest::from_dir("markdown/tasklists").check_main_file(
89 "book/tasklists.html",
90 str![[r##"
91 <h2 id="tasklisks"><a class="header" href="#tasklisks">Tasklisks</a></h2>
92 <ul>
93 <li><input disabled="" type="checkbox" checked=""> Apples</li>
94 <li><input disabled="" type="checkbox" checked=""> Broccoli</li>
95 <li><input disabled="" type="checkbox"> Carrots</li>
96 </ul>
97 "##]],
98 );
99 }
100
101 // Smart punctuation test.
102 #[test]
103 fn smart_punctuation() {
104 BookTest::from_dir("markdown/smart_punctuation")
105 // Default is on.
106 .check_main_file(
107 "book/smart_punctuation.html",
108 str![[r##"
109 <h1 id="smart-punctuation"><a class="header" href="#smart-punctuation">Smart Punctuation</a></h1>
110 <ul>
111 <li>En dash: –</li>
112 <li>Em dash: —</li>
113 <li>Ellipsis: …</li>
114 <li>Double quote: “quote”</li>
115 <li>Single quote: ‘quote’</li>
116 <li>Quote in <code>"code"</code></li>
117 </ul>
118 <pre><code>"quoted"
119 </code></pre>
120 "##]],
121 )
122 .run("build", |cmd| {
123 cmd.env("MDBOOK_OUTPUT__HTML__SMART_PUNCTUATION", "false");
124 })
125 .check_main_file(
126 "book/smart_punctuation.html",
127 str![[r##"
128 <h1 id="smart-punctuation"><a class="header" href="#smart-punctuation">Smart Punctuation</a></h1>
129 <ul>
130 <li>En dash: --</li>
131 <li>Em dash: ---</li>
132 <li>Ellipsis: ...</li>
133 <li>Double quote: "quote"</li>
134 <li>Single quote: 'quote'</li>
135 <li>Quote in <code>"code"</code></li>
136 </ul>
137 <pre><code>"quoted"
138 </code></pre>
139 "##]],
140 );
141 }
142
143 // Basic markdown syntax.
144 // This doesn't try to cover the commonmark test suite, but maybe it could some day?
145 #[test]
146 fn basic_markdown() {
147 BookTest::from_dir("markdown/basic_markdown").check_all_main_files();
148 }
149
150 #[test]
151 fn definition_lists() {
152 BookTest::from_dir("markdown/definition_lists")
153 .check_all_main_files()
154 .run("build", |cmd| {
155 cmd.env("MDBOOK_OUTPUT__HTML__DEFINITION_LISTS", "false");
156 })
157 .check_main_file(
158 "book/definition_lists.html",
159 file!["markdown/definition_lists/expected_disabled/definition_lists.html"],
160 )
161 .check_main_file(
162 "book/html_definition_lists.html",
163 file!["markdown/definition_lists/expected_disabled/html_definition_lists.html"],
164 );
165 }
166
167 #[test]
168 fn admonitions() {
169 BookTest::from_dir("markdown/admonitions")
170 .check_all_main_files()
171 .run("build", |cmd| {
172 cmd.env("MDBOOK_OUTPUT__HTML__ADMONITIONS", "false");
173 })
174 .check_main_file(
175 "book/admonitions.html",
176 file!["markdown/admonitions/expected_disabled/admonitions.html"],
177 );
178 }