Migrate markdown_options to BookTest
This commit is contained in:
parent
0732cb47b9
commit
74e01ea6e3
11 changed files with 159 additions and 64 deletions
|
|
@ -374,70 +374,6 @@ fn no_index_for_print_html() {
|
|||
assert_doesnt_contain_strings(index_html, &[r##"noindex"##]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn markdown_options() {
|
||||
let temp = DummyBook::new().build().unwrap();
|
||||
let md = MDBook::load(temp.path()).unwrap();
|
||||
md.build().unwrap();
|
||||
|
||||
let path = temp.path().join("book/first/markdown.html");
|
||||
assert_contains_strings(
|
||||
&path,
|
||||
&[
|
||||
"<th>foo</th>",
|
||||
"<th>bar</th>",
|
||||
"<td>baz</td>",
|
||||
"<td>bim</td>",
|
||||
],
|
||||
);
|
||||
assert_contains_strings(
|
||||
&path,
|
||||
&[
|
||||
r##"<sup class="footnote-reference" id="fr-1-1"><a href="#footnote-1">1</a></sup>"##,
|
||||
r##"<sup class="footnote-reference" id="fr-word-1"><a href="#footnote-word">2</a></sup>"##,
|
||||
r##"<sup class="footnote-reference" id="fr-word-2"><a href="#footnote-word">2</a></sup>"##,
|
||||
r##"<hr>
|
||||
<ol class="footnote-definition"><li id="footnote-1">
|
||||
<p>This is a footnote. <a href="#fr-1-1">↩</a> <a href="#fr-1-2">↩2</a></p>
|
||||
</li>
|
||||
<li id="footnote-word">
|
||||
<p>A longer footnote.
|
||||
With multiple lines. <a href="unicode.html">Link to unicode</a>.
|
||||
With a reference inside.<sup class="footnote-reference" id="fr-1-2"><a href="#footnote-1">1</a></sup> <a href="#fr-word-1">↩</a> <a href="#fr-word-2">↩2</a></p>
|
||||
</li>
|
||||
<li id="footnote-para">
|
||||
<ol>
|
||||
<li>Item one
|
||||
<ol>
|
||||
<li>Sub-item</li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>Item two</li>
|
||||
</ol>
|
||||
<a href="#fr-para-1">↩</a></li>
|
||||
<li id="footnote-multiple"><p>One</p><p>Two</p><p>Three</p>
|
||||
<a href="#fr-multiple-1">↩</a></li>
|
||||
<li id="footnote-"wacky"">
|
||||
<p>Testing footnote id with special characters. <a href="#fr-"wacky"-1">↩</a></p>
|
||||
</li>
|
||||
<li id="footnote-define-before-use">
|
||||
<p>This is defined before it is referred to. <a href="#fr-define-before-use-1">↩</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
"##,
|
||||
],
|
||||
);
|
||||
assert_contains_strings(&path, &["<del>strikethrough example</del>"]);
|
||||
assert_contains_strings(
|
||||
&path,
|
||||
&[
|
||||
"<li><input disabled=\"\" type=\"checkbox\" checked=\"\"/>\nApples",
|
||||
"<li><input disabled=\"\" type=\"checkbox\" checked=\"\"/>\nBroccoli",
|
||||
"<li><input disabled=\"\" type=\"checkbox\"/>\nCarrots",
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn redirects_are_emitted_correctly() {
|
||||
let temp = DummyBook::new().build().unwrap();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ mod cli;
|
|||
mod includes;
|
||||
mod index;
|
||||
mod init;
|
||||
mod markdown;
|
||||
|
||||
mod prelude {
|
||||
pub use crate::book_test::BookTest;
|
||||
|
|
|
|||
99
tests/testsuite/markdown.rs
Normal file
99
tests/testsuite/markdown.rs
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
//! Tests for special markdown rendering.
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
// Test for a variety of footnote renderings.
|
||||
#[test]
|
||||
fn footnotes() {
|
||||
BookTest::from_dir("markdown/footnotes")
|
||||
.check_main_file("book/footnotes.html", str![[r##"
|
||||
<h1 id="footnote-tests"><a class="header" href="#footnote-tests">Footnote tests</a></h1>
|
||||
<p>Footnote example<sup class="footnote-reference" id="fr-1-1"><a href="#footnote-1">1</a></sup>, or with a word<sup class="footnote-reference" id="fr-word-1"><a href="#footnote-word">2</a></sup>.</p>
|
||||
<p>There are multiple references to word<sup class="footnote-reference" id="fr-word-2"><a href="#footnote-word">2</a></sup>.</p>
|
||||
<p>Footnote without a paragraph<sup class="footnote-reference" id="fr-para-1"><a href="#footnote-para">3</a></sup></p>
|
||||
<p>Footnote with multiple paragraphs<sup class="footnote-reference" id="fr-multiple-1"><a href="#footnote-multiple">4</a></sup></p>
|
||||
<p>Footnote name with wacky characters<sup class="footnote-reference" id="fr-"wacky"-1"><a href="#footnote-"wacky"">5</a></sup></p>
|
||||
<p>Testing when referring to something earlier.<sup class="footnote-reference" id="fr-define-before-use-1"><a href="#footnote-define-before-use">6</a></sup></p>
|
||||
<hr>
|
||||
<ol class="footnote-definition"><li id="footnote-1">
|
||||
<p>This is a footnote. <a href="#fr-1-1">↩</a> <a href="#fr-1-2">↩2</a></p>
|
||||
</li>
|
||||
<li id="footnote-word">
|
||||
<p>A longer footnote.
|
||||
With multiple lines. <a href="other.html">Link to other</a>.
|
||||
With a reference inside.<sup class="footnote-reference" id="fr-1-2"><a href="#footnote-1">1</a></sup> <a href="#fr-word-1">↩</a> <a href="#fr-word-2">↩2</a></p>
|
||||
</li>
|
||||
<li id="footnote-para">
|
||||
<ol>
|
||||
<li>Item one
|
||||
<ol>
|
||||
<li>Sub-item</li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>Item two</li>
|
||||
</ol>
|
||||
<a href="#fr-para-1">↩</a></li>
|
||||
<li id="footnote-multiple">
|
||||
<p>One</p>
|
||||
<p>Two</p>
|
||||
<p>Three <a href="#fr-multiple-1">↩</a></p>
|
||||
</li>
|
||||
<li id="footnote-"wacky"">
|
||||
<p>Testing footnote id with special characters. <a href="#fr-"wacky"-1">↩</a></p>
|
||||
</li>
|
||||
<li id="footnote-define-before-use">
|
||||
<p>This is defined before it is referred to. <a href="#fr-define-before-use-1">↩</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
"##]]);
|
||||
}
|
||||
|
||||
// Basic table test.
|
||||
#[test]
|
||||
fn tables() {
|
||||
BookTest::from_dir("markdown/tables").check_main_file(
|
||||
"book/tables.html",
|
||||
str![[r##"
|
||||
<h1 id="tables"><a class="header" href="#tables">Tables</a></h1>
|
||||
<div class="table-wrapper"><table><thead><tr><th>foo</th><th>bar</th></tr></thead><tbody>
|
||||
<tr><td>baz</td><td>bim</td></tr>
|
||||
<tr><td>Backslash in code</td><td><code>/</code></td></tr>
|
||||
<tr><td>Double back in code</td><td><code>//</code></td></tr>
|
||||
<tr><td>Pipe in code</td><td><code>|</code></td></tr>
|
||||
<tr><td>Pipe in code2</td><td><code>test | inside</code></td></tr>
|
||||
</tbody></table>
|
||||
</div>
|
||||
"##]],
|
||||
);
|
||||
}
|
||||
|
||||
// Strikethrough test.
|
||||
#[test]
|
||||
fn strikethrough() {
|
||||
BookTest::from_dir("markdown/strikethrough").check_main_file(
|
||||
"book/strikethrough.html",
|
||||
str![[r##"
|
||||
<h1 id="strikethrough"><a class="header" href="#strikethrough">Strikethrough</a></h1>
|
||||
<p><del>strikethrough example</del></p>
|
||||
"##]],
|
||||
);
|
||||
}
|
||||
|
||||
// Tasklist test.
|
||||
#[test]
|
||||
fn tasklists() {
|
||||
BookTest::from_dir("markdown/tasklists").check_main_file(
|
||||
"book/tasklists.html",
|
||||
str![[r##"
|
||||
<h2 id="tasklisks"><a class="header" href="#tasklisks">Tasklisks</a></h2>
|
||||
<ul>
|
||||
<li><input disabled="" type="checkbox" checked=""/>
|
||||
Apples</li>
|
||||
<li><input disabled="" type="checkbox" checked=""/>
|
||||
Broccoli</li>
|
||||
<li><input disabled="" type="checkbox"/>
|
||||
Carrots</li>
|
||||
</ul>
|
||||
"##]],
|
||||
);
|
||||
}
|
||||
1
tests/testsuite/markdown/footnotes/src/SUMMARY.md
Normal file
1
tests/testsuite/markdown/footnotes/src/SUMMARY.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
- [Footnotes](footnotes.md)
|
||||
37
tests/testsuite/markdown/footnotes/src/footnotes.md
Normal file
37
tests/testsuite/markdown/footnotes/src/footnotes.md
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# Footnote tests
|
||||
|
||||
Footnote example[^1], or with a word[^word].
|
||||
|
||||
[^1]: This is a footnote.
|
||||
|
||||
[^word]: A longer footnote.
|
||||
With multiple lines. [Link to other](other.md).
|
||||
With a reference inside.[^1]
|
||||
|
||||
There are multiple references to word[^word].
|
||||
|
||||
Footnote without a paragraph[^para]
|
||||
|
||||
[^para]:
|
||||
1. Item one
|
||||
1. Sub-item
|
||||
2. Item two
|
||||
|
||||
Footnote with multiple paragraphs[^multiple]
|
||||
|
||||
[^define-before-use]: This is defined before it is referred to.
|
||||
|
||||
[^multiple]:
|
||||
One
|
||||
|
||||
Two
|
||||
|
||||
Three
|
||||
|
||||
[^unused]: This footnote is defined by not used.
|
||||
|
||||
Footnote name with wacky characters[^"wacky"]
|
||||
|
||||
[^"wacky"]: Testing footnote id with special characters.
|
||||
|
||||
Testing when referring to something earlier.[^define-before-use]
|
||||
1
tests/testsuite/markdown/strikethrough/src/SUMMARY.md
Normal file
1
tests/testsuite/markdown/strikethrough/src/SUMMARY.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
- [Strikethrough](strikethrough.md)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# Strikethrough
|
||||
|
||||
~~strikethrough example~~
|
||||
|
||||
1
tests/testsuite/markdown/tables/src/SUMMARY.md
Normal file
1
tests/testsuite/markdown/tables/src/SUMMARY.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
- [Tables](tables.md)
|
||||
9
tests/testsuite/markdown/tables/src/tables.md
Normal file
9
tests/testsuite/markdown/tables/src/tables.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Tables
|
||||
|
||||
| foo | bar |
|
||||
| --- | --- |
|
||||
| baz | bim |
|
||||
| Backslash in code | `\` |
|
||||
| Double back in code | `\\` |
|
||||
| Pipe in code | `\|` |
|
||||
| Pipe in code2 | `test \| inside` |
|
||||
1
tests/testsuite/markdown/tasklists/src/SUMMARY.md
Normal file
1
tests/testsuite/markdown/tasklists/src/SUMMARY.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
- [Tasklists](tasklists.md)
|
||||
5
tests/testsuite/markdown/tasklists/src/tasklists.md
Normal file
5
tests/testsuite/markdown/tasklists/src/tasklists.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
## Tasklisks
|
||||
|
||||
- [X] Apples
|
||||
- [X] Broccoli
|
||||
- [ ] Carrots
|
||||
Loading…
Add table
Reference in a new issue