Migrate check_correct_relative_links_in_print_page to BookTest
This commit is contained in:
parent
5034707a73
commit
3e22a5cdad
8 changed files with 49 additions and 21 deletions
|
|
@ -72,27 +72,6 @@ fn check_correct_cross_links_in_nested_dir() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_correct_relative_links_in_print_page() {
|
||||
let temp = DummyBook::new().build().unwrap();
|
||||
let md = MDBook::load(temp.path()).unwrap();
|
||||
md.build().unwrap();
|
||||
|
||||
let first = temp.path().join("book");
|
||||
|
||||
assert_contains_strings(
|
||||
first.join("print.html"),
|
||||
&[
|
||||
r##"<a href="second/../first/nested.html">the first section</a>,"##,
|
||||
r##"<a href="second/../../std/foo/bar.html">outside</a>"##,
|
||||
r##"<img src="second/../images/picture.png" alt="Some image" />"##,
|
||||
r##"<a href="second/nested.html#some-section">fragment link</a>"##,
|
||||
r##"<a href="second/../first/markdown.html">HTML Link</a>"##,
|
||||
r##"<img src="second/../images/picture.png" alt="raw html">"##,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chapter_content_appears_in_rendered_document() {
|
||||
let content = vec![
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ mod init;
|
|||
mod markdown;
|
||||
mod playground;
|
||||
mod preprocessor;
|
||||
mod print;
|
||||
|
||||
mod prelude {
|
||||
pub use crate::book_test::BookTest;
|
||||
|
|
|
|||
23
tests/testsuite/print.rs
Normal file
23
tests/testsuite/print.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//! Tests for print page.
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
// Tests relative links from the print page.
|
||||
#[test]
|
||||
fn relative_links() {
|
||||
BookTest::from_dir("print/relative_links")
|
||||
.check_main_file("book/print.html",
|
||||
str![[r##"
|
||||
<h1 id="first-chapter"><a class="header" href="#first-chapter">First Chapter</a></h1>
|
||||
<div style="break-before: page; page-break-before: always;"></div><h1 id="first-nested"><a class="header" href="#first-nested">First Nested</a></h1>
|
||||
<div style="break-before: page; page-break-before: always;"></div><h1 id="testing-relative-links-for-the-print-page"><a class="header" href="#testing-relative-links-for-the-print-page">Testing relative links for the print page</a></h1>
|
||||
<p>When we link to <a href="second/../first/nested.html">the first section</a>, it should work on
|
||||
both the print page and the non-print page.</p>
|
||||
<p>A <a href="second/nested.html#some-section">fragment link</a> should work.</p>
|
||||
<p>Link <a href="second/../../std/foo/bar.html">outside</a>.</p>
|
||||
<p><img src="second/../images/picture.png" alt="Some image" /></p>
|
||||
<p><a href="second/../first/markdown.html">HTML Link</a></p>
|
||||
<img src="second/../images/picture.png" alt="raw html">
|
||||
<h2 id="some-section"><a class="header" href="#some-section">Some section</a></h2>
|
||||
"##]]);
|
||||
}
|
||||
2
tests/testsuite/print/relative_links/book.toml
Normal file
2
tests/testsuite/print/relative_links/book.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[book]
|
||||
title = "relative_links"
|
||||
5
tests/testsuite/print/relative_links/src/SUMMARY.md
Normal file
5
tests/testsuite/print/relative_links/src/SUMMARY.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Summary
|
||||
|
||||
- [First Chapter](first/index.md)
|
||||
- [First Nested](first/nested.md)
|
||||
- [Second Chapter](second/nested.md)
|
||||
1
tests/testsuite/print/relative_links/src/first/index.md
Normal file
1
tests/testsuite/print/relative_links/src/first/index.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
# First Chapter
|
||||
1
tests/testsuite/print/relative_links/src/first/nested.md
Normal file
1
tests/testsuite/print/relative_links/src/first/nested.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
# First Nested
|
||||
16
tests/testsuite/print/relative_links/src/second/nested.md
Normal file
16
tests/testsuite/print/relative_links/src/second/nested.md
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Testing relative links for the print page
|
||||
|
||||
When we link to [the first section](../first/nested.md), it should work on
|
||||
both the print page and the non-print page.
|
||||
|
||||
A [fragment link](#some-section) should work.
|
||||
|
||||
Link [outside](../../std/foo/bar.html).
|
||||
|
||||

|
||||
|
||||
<a href="../first/markdown.md">HTML Link</a>
|
||||
|
||||
<img src="../images/picture.png" alt="raw html">
|
||||
|
||||
## Some section
|
||||
Loading…
Add table
Reference in a new issue