diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/mdbook/tests/dummy_book | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/mdbook/tests/dummy_book')
28 files changed, 386 insertions, 0 deletions
diff --git a/vendor/mdbook/tests/dummy_book/index_html_test/SUMMARY.md b/vendor/mdbook/tests/dummy_book/index_html_test/SUMMARY.md new file mode 100644 index 000000000..37bf68cde --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/index_html_test/SUMMARY.md @@ -0,0 +1,11 @@ +# Summary + +--- + +- [None of these should be treated as the "index chapter"]() + +# Part 1 + +- [Not this either]() +- [Chapter 1](./chapter_1.md) +- [And not this]() diff --git a/vendor/mdbook/tests/dummy_book/index_html_test/chapter_1.md b/vendor/mdbook/tests/dummy_book/index_html_test/chapter_1.md new file mode 100644 index 000000000..b743fda35 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/index_html_test/chapter_1.md @@ -0,0 +1 @@ +# Chapter 1 diff --git a/vendor/mdbook/tests/dummy_book/mod.rs b/vendor/mdbook/tests/dummy_book/mod.rs new file mode 100644 index 000000000..d9d9a068d --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/mod.rs @@ -0,0 +1,145 @@ +//! This will create an entire book in a temporary directory using some +//! dummy contents from the `tests/dummy-book/` directory. + +// Not all features are used in all test crates, so... +#![allow(dead_code, unused_variables, unused_imports, unused_extern_crates)] + +use anyhow::Context; +use mdbook::errors::*; +use mdbook::MDBook; +use std::fs::{self, File}; +use std::io::{Read, Write}; +use std::path::Path; +use tempfile::{Builder as TempFileBuilder, TempDir}; +use walkdir::WalkDir; + +/// Create a dummy book in a temporary directory, using the contents of +/// `SUMMARY_MD` as a guide. +/// +/// The "Nested Chapter" file contains a code block with a single +/// `assert!($TEST_STATUS)`. If you want to check MDBook's testing +/// functionality, `$TEST_STATUS` can be substitute for either `true` or +/// `false`. This is done using the `passing_test` parameter. +#[derive(Clone, Debug, PartialEq)] +pub struct DummyBook { + passing_test: bool, +} + +impl DummyBook { + /// Create a new `DummyBook` with all the defaults. + pub fn new() -> DummyBook { + DummyBook { passing_test: true } + } + + /// Whether the doc-test included in the "Nested Chapter" should pass or + /// fail (it passes by default). + pub fn with_passing_test(&mut self, test_passes: bool) -> &mut DummyBook { + self.passing_test = test_passes; + self + } + + /// Write a book to a temporary directory using the provided settings. + pub fn build(&self) -> Result<TempDir> { + let temp = TempFileBuilder::new() + .prefix("dummy_book-") + .tempdir() + .with_context(|| "Unable to create temp directory")?; + + let dummy_book_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/dummy_book"); + recursive_copy(&dummy_book_root, temp.path()).with_context(|| { + "Couldn't copy files into a \ + temporary directory" + })?; + + let sub_pattern = if self.passing_test { "true" } else { "false" }; + let files_containing_tests = [ + "src/first/nested.md", + "src/first/nested-test.rs", + "src/first/nested-test-with-anchors.rs", + "src/first/partially-included-test.rs", + "src/first/partially-included-test-with-anchors.rs", + ]; + for file in &files_containing_tests { + let path_containing_tests = temp.path().join(file); + replace_pattern_in_file(&path_containing_tests, "$TEST_STATUS", sub_pattern)?; + } + + Ok(temp) + } +} + +fn replace_pattern_in_file(filename: &Path, from: &str, to: &str) -> Result<()> { + let contents = fs::read_to_string(filename)?; + File::create(filename)?.write_all(contents.replace(from, to).as_bytes())?; + + Ok(()) +} + +/// Read the contents of the provided file into memory and then iterate through +/// the list of strings asserting that the file contains all of them. +pub fn assert_contains_strings<P: AsRef<Path>>(filename: P, strings: &[&str]) { + let filename = filename.as_ref(); + let content = fs::read_to_string(filename).expect("Couldn't read the file's contents"); + + for s in strings { + assert!( + content.contains(s), + "Searching for {:?} in {}\n\n{}", + s, + filename.display(), + content + ); + } +} + +pub fn assert_doesnt_contain_strings<P: AsRef<Path>>(filename: P, strings: &[&str]) { + let filename = filename.as_ref(); + let content = fs::read_to_string(filename).expect("Couldn't read the file's contents"); + + for s in strings { + assert!( + !content.contains(s), + "Found {:?} in {}\n\n{}", + s, + filename.display(), + content + ); + } +} + +/// Recursively copy an entire directory tree to somewhere else (a la `cp -r`). +fn recursive_copy<A: AsRef<Path>, B: AsRef<Path>>(from: A, to: B) -> Result<()> { + let from = from.as_ref(); + let to = to.as_ref(); + + for entry in WalkDir::new(&from) { + let entry = entry.with_context(|| "Unable to inspect directory entry")?; + + let original_location = entry.path(); + let relative = original_location + .strip_prefix(&from) + .expect("`original_location` is inside the `from` directory"); + let new_location = to.join(relative); + + if original_location.is_file() { + if let Some(parent) = new_location.parent() { + fs::create_dir_all(parent).with_context(|| "Couldn't create directory")?; + } + + fs::copy(&original_location, &new_location) + .with_context(|| "Unable to copy file contents")?; + } + } + + Ok(()) +} + +pub fn new_copy_of_example_book() -> Result<TempDir> { + let temp = TempFileBuilder::new().prefix("guide").tempdir()?; + + let guide = Path::new(env!("CARGO_MANIFEST_DIR")).join("guide"); + + recursive_copy(guide, temp.path())?; + + Ok(temp) +} diff --git a/vendor/mdbook/tests/dummy_book/src/README.md b/vendor/mdbook/tests/dummy_book/src/README.md new file mode 100644 index 000000000..7d946e35d --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/README.md @@ -0,0 +1,5 @@ +# Dummy Book + +This file is just here to cause the index preprocessor to run. + +Does a pretty good job, too.
\ No newline at end of file diff --git a/vendor/mdbook/tests/dummy_book/src/SUMMARY.md b/vendor/mdbook/tests/dummy_book/src/SUMMARY.md new file mode 100644 index 000000000..49b64a545 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/SUMMARY.md @@ -0,0 +1,22 @@ +# Summary + +[Dummy Book](README.md) + +--- + +[Introduction](intro.md) + +- [First Chapter](first/index.md) + - [Nested Chapter](first/nested.md) + - [Includes](first/includes.md) + - [Recursive](first/recursive.md) + - [Markdown](first/markdown.md) + - [Unicode](first/unicode.md) + - [No Headers](first/no-headers.md) + - [Duplicate Headers](first/duplicate-headers.md) +- [Second Chapter](second.md) + - [Nested Chapter](second/nested.md) + +--- + +[Conclusion](conclusion.md) diff --git a/vendor/mdbook/tests/dummy_book/src/conclusion.md b/vendor/mdbook/tests/dummy_book/src/conclusion.md new file mode 100644 index 000000000..ba121c1fd --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/conclusion.md @@ -0,0 +1,20 @@ +# Conclusion + +<p> +<!--secret secret--> +I put <HTML> in here!<br/> +</p> +<script type="text/javascript" > +// I probably shouldn't do this +if (3 < 5 > 10) +{ + alert("The sky is falling!"); +} +</script > +<style > +/* +css looks, like this { + foo: < 3 <bar > +} +*/ +</style> diff --git a/vendor/mdbook/tests/dummy_book/src/example.rs b/vendor/mdbook/tests/dummy_book/src/example.rs new file mode 100644 index 000000000..6b49705c1 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/example.rs @@ -0,0 +1,6 @@ +fn main() { + println!("Hello World!"); +# +# // You can even hide lines! :D +# println!("I am hidden! Expand the code snippet to see me"); +} diff --git a/vendor/mdbook/tests/dummy_book/src/first/duplicate-headers.md b/vendor/mdbook/tests/dummy_book/src/first/duplicate-headers.md new file mode 100644 index 000000000..83522b440 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/duplicate-headers.md @@ -0,0 +1,9 @@ +# Duplicate headers + +This page validates behaviour of duplicate headers. + +# Header Text + +# Header Text + +# header-text diff --git a/vendor/mdbook/tests/dummy_book/src/first/includes.md b/vendor/mdbook/tests/dummy_book/src/first/includes.md new file mode 100644 index 000000000..a5a2fef1f --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/includes.md @@ -0,0 +1,3 @@ +# Includes + +{{#include ../SUMMARY.md::}}
\ No newline at end of file diff --git a/vendor/mdbook/tests/dummy_book/src/first/index.md b/vendor/mdbook/tests/dummy_book/src/first/index.md new file mode 100644 index 000000000..200672b9c --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/index.md @@ -0,0 +1,5 @@ +# First Chapter + +more text. + +## Some Section diff --git a/vendor/mdbook/tests/dummy_book/src/first/markdown.md b/vendor/mdbook/tests/dummy_book/src/first/markdown.md new file mode 100644 index 000000000..d65d3d389 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/markdown.md @@ -0,0 +1,29 @@ +# Markdown tests + +Tests for some markdown output. + +## Tables + +| foo | bar | +| --- | --- | +| baz | bim | + +## Footnotes + +Footnote example[^1], or with a word[^word]. + +[^1]: This is a footnote. + +[^word]: A longer footnote. + With multiple lines. + Third line. + +## Strikethrough + +~~strikethrough example~~ + +## Tasklisks + +- [X] Apples +- [X] Broccoli +- [ ] Carrots diff --git a/vendor/mdbook/tests/dummy_book/src/first/nested-test-with-anchors.rs b/vendor/mdbook/tests/dummy_book/src/first/nested-test-with-anchors.rs new file mode 100644 index 000000000..783ab14de --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/nested-test-with-anchors.rs @@ -0,0 +1,11 @@ +// The next line will cause a `testing` test to fail if the anchor feature is broken in such a way +// that the whole file gets mistakenly included. +assert!(!$TEST_STATUS); + +// ANCHOR: myanchor +// ANCHOR: unendinganchor +// The next line will cause a `rendered_output` test to fail if the anchor feature is broken in +// such a way that the content between anchors isn't included. +// unique-string-for-anchor-test +assert!($TEST_STATUS); +// ANCHOR_END: myanchor diff --git a/vendor/mdbook/tests/dummy_book/src/first/nested-test.rs b/vendor/mdbook/tests/dummy_book/src/first/nested-test.rs new file mode 100644 index 000000000..2bc46e01a --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/nested-test.rs @@ -0,0 +1 @@ +assert!($TEST_STATUS); diff --git a/vendor/mdbook/tests/dummy_book/src/first/nested.md b/vendor/mdbook/tests/dummy_book/src/first/nested.md new file mode 100644 index 000000000..ae90763a0 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/nested.md @@ -0,0 +1,31 @@ +# Nested Chapter + +This file has some testable code. + +```rust +assert!($TEST_STATUS); +``` + +## Some Section + +```rust +{{#include nested-test.rs}} +``` + +## Anchors include the part of a file between special comments + +```rust +{{#include nested-test-with-anchors.rs:myanchor}} +``` + +## Rustdoc include adds the rest of the file as hidden + +```rust +{{#rustdoc_include partially-included-test.rs:5:7}} +``` + +## Rustdoc include works with anchors too + +```rust +{{#rustdoc_include partially-included-test-with-anchors.rs:rustdoc-include-anchor}} +``` diff --git a/vendor/mdbook/tests/dummy_book/src/first/no-headers.md b/vendor/mdbook/tests/dummy_book/src/first/no-headers.md new file mode 100644 index 000000000..5d799aa68 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/no-headers.md @@ -0,0 +1,5 @@ +Capybara capybara capybara. + +Capybara capybara capybara. + +ThisLongWordIsIncludedSoWeCanCheckThatSufficientlyLongWordsAreOmittedFromTheSearchIndex. diff --git a/vendor/mdbook/tests/dummy_book/src/first/partially-included-test-with-anchors.rs b/vendor/mdbook/tests/dummy_book/src/first/partially-included-test-with-anchors.rs new file mode 100644 index 000000000..17b6afeff --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/partially-included-test-with-anchors.rs @@ -0,0 +1,11 @@ +fn some_other_function() { + // ANCHOR: unused-anchor-that-should-be-stripped + assert!($TEST_STATUS); + // ANCHOR_END: unused-anchor-that-should-be-stripped +} + +// ANCHOR: rustdoc-include-anchor +fn main() { + some_other_function(); +} +// ANCHOR_END: rustdoc-include-anchor diff --git a/vendor/mdbook/tests/dummy_book/src/first/partially-included-test.rs b/vendor/mdbook/tests/dummy_book/src/first/partially-included-test.rs new file mode 100644 index 000000000..1f8421b54 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/partially-included-test.rs @@ -0,0 +1,7 @@ +fn some_function() { + assert!($TEST_STATUS); +} + +fn main() { + some_function(); +} diff --git a/vendor/mdbook/tests/dummy_book/src/first/recursive.md b/vendor/mdbook/tests/dummy_book/src/first/recursive.md new file mode 100644 index 000000000..cb82a52f1 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/recursive.md @@ -0,0 +1,2 @@ +Around the world, around the world +{{#include recursive.md}} diff --git a/vendor/mdbook/tests/dummy_book/src/first/unicode.md b/vendor/mdbook/tests/dummy_book/src/first/unicode.md new file mode 100644 index 000000000..160cc367d --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/first/unicode.md @@ -0,0 +1,21 @@ +# Unicode stress tests + +Please be careful editing, this contains carefully crafted characters. + +Two byte character: spatiëring + +Combining character: spatiëring + +Three byte character: 书こんにちは + +Four byte character: 𐌀𐌁𐌂𐌃𐌄𐌅𐌆𐌇𐌈 + +Right-to-left: مرحبا + +Emoticons: 🔊 😍 💜 1️⃣ + +right-to-left mark: hello באמת! + + +Zalgo: ǫ̛̖̱̗̝͈̋͒͋̏ͥͫ̒̆ͩ̏͌̾͊͐ͪ̾̚ + diff --git a/vendor/mdbook/tests/dummy_book/src/intro.md b/vendor/mdbook/tests/dummy_book/src/intro.md new file mode 100644 index 000000000..1990ef58c --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/intro.md @@ -0,0 +1,3 @@ +# Introduction + +Here's some interesting text...
\ No newline at end of file diff --git a/vendor/mdbook/tests/dummy_book/src/second.md b/vendor/mdbook/tests/dummy_book/src/second.md new file mode 100644 index 000000000..adf4fca62 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/second.md @@ -0,0 +1,5 @@ +# Second Chapter + +This makes sure you can insert runnable Rust files. + +{{#playground example.rs}} diff --git a/vendor/mdbook/tests/dummy_book/src/second/nested.md b/vendor/mdbook/tests/dummy_book/src/second/nested.md new file mode 100644 index 000000000..faf1187ff --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src/second/nested.md @@ -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). + +![Some image](../images/picture.png) + +<a href="../first/markdown.md">HTML Link</a> + +<img src="../images/picture.png" alt="raw html"> + +## Some section diff --git a/vendor/mdbook/tests/dummy_book/src2/README.md b/vendor/mdbook/tests/dummy_book/src2/README.md new file mode 100644 index 000000000..ba23d94ef --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src2/README.md @@ -0,0 +1 @@ +# Root README diff --git a/vendor/mdbook/tests/dummy_book/src2/SUMMARY.md b/vendor/mdbook/tests/dummy_book/src2/SUMMARY.md new file mode 100644 index 000000000..6b279fc48 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src2/SUMMARY.md @@ -0,0 +1,7 @@ +# This dummy book is for testing the conversion of README.md to index.html by IndexPreprocessor + +[Root README](README.md) + +- [1st README](first/README.md) +- [2nd README](second/README.md) + - [2nd index](second/index.md) diff --git a/vendor/mdbook/tests/dummy_book/src2/first/README.md b/vendor/mdbook/tests/dummy_book/src2/first/README.md new file mode 100644 index 000000000..d062d2ccd --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src2/first/README.md @@ -0,0 +1 @@ +# First README diff --git a/vendor/mdbook/tests/dummy_book/src2/second/README.md b/vendor/mdbook/tests/dummy_book/src2/second/README.md new file mode 100644 index 000000000..be81f856f --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src2/second/README.md @@ -0,0 +1 @@ +# Second README diff --git a/vendor/mdbook/tests/dummy_book/src2/second/index.md b/vendor/mdbook/tests/dummy_book/src2/second/index.md new file mode 100644 index 000000000..f23274504 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/src2/second/index.md @@ -0,0 +1 @@ +# Second index diff --git a/vendor/mdbook/tests/dummy_book/summary-formatting/SUMMARY.md b/vendor/mdbook/tests/dummy_book/summary-formatting/SUMMARY.md new file mode 100644 index 000000000..336218d82 --- /dev/null +++ b/vendor/mdbook/tests/dummy_book/summary-formatting/SUMMARY.md @@ -0,0 +1,6 @@ +# Summary formatting tests + +- [*Italic* `code` \*escape\* \`escape2\`](formatted-summary.md) +- [Soft +line break](soft.md) +- [\<escaped tag\>](escaped-tag.md) |