From d23bdaa527d3e68636ee8dc1e0da76a61278bef6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 22 Apr 2025 08:54:31 -0700 Subject: [PATCH] Migrate edit-url-template tests to BookTest --- tests/rendered_output.rs | 53 +------------------ tests/testsuite/main.rs | 1 + tests/testsuite/rendering.rs | 23 ++++++++ .../rendering/edit_url_template/book.toml | 5 ++ .../edit_url_template/src/SUMMARY.md | 1 + .../edit_url_template_explicit_src/book.toml | 6 +++ .../src2/SUMMARY.md | 1 + 7 files changed, 38 insertions(+), 52 deletions(-) create mode 100644 tests/testsuite/rendering.rs create mode 100644 tests/testsuite/rendering/edit_url_template/book.toml create mode 100644 tests/testsuite/rendering/edit_url_template/src/SUMMARY.md create mode 100644 tests/testsuite/rendering/edit_url_template_explicit_src/book.toml create mode 100644 tests/testsuite/rendering/edit_url_template_explicit_src/src2/SUMMARY.md diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index c75464b9..c935fae0 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -13,7 +13,7 @@ use select::document::Document; use select::predicate::{Attr, Class, Name, Predicate}; use std::ffi::OsStr; use std::fs; -use std::path::{Component, Path, PathBuf}; +use std::path::{Path, PathBuf}; use std::str::FromStr; use tempfile::Builder as TempFileBuilder; use walkdir::{DirEntry, WalkDir}; @@ -304,57 +304,6 @@ fn theme_dir_overrides_work_correctly() { dummy_book::assert_contains_strings(built_index, &["This is a modified index.hbs!"]); } -#[test] -fn edit_url_has_default_src_dir_edit_url() { - let temp = DummyBook::new().build().unwrap(); - let book_toml = r#" - [book] - title = "implicit" - - [output.html] - edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}" - "#; - - write_file(temp.path(), "book.toml", book_toml.as_bytes()).unwrap(); - - let md = MDBook::load(temp.path()).unwrap(); - md.build().unwrap(); - - let index_html = temp.path().join("book").join("index.html"); - assert_contains_strings( - index_html, - &[ - r#"href="https://github.com/rust-lang/mdBook/edit/master/guide/src/README.md" title="Suggest an edit""#, - ], - ); -} - -#[test] -fn edit_url_has_configured_src_dir_edit_url() { - let temp = DummyBook::new().build().unwrap(); - let book_toml = r#" - [book] - title = "implicit" - src = "src2" - - [output.html] - edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}" - "#; - - write_file(temp.path(), "book.toml", book_toml.as_bytes()).unwrap(); - - let md = MDBook::load(temp.path()).unwrap(); - md.build().unwrap(); - - let index_html = temp.path().join("book").join("index.html"); - assert_contains_strings( - index_html, - &[ - r#"href="https://github.com/rust-lang/mdBook/edit/master/guide/src2/README.md" title="Suggest an edit""#, - ], - ); -} - /// Checks formatting of summary names with inline elements. #[test] fn summary_with_markdown_formatting() { diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 5c030213..38c60999 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -14,6 +14,7 @@ mod preprocessor; mod print; mod redirects; mod renderer; +mod rendering; mod prelude { pub use crate::book_test::BookTest; diff --git a/tests/testsuite/rendering.rs b/tests/testsuite/rendering.rs new file mode 100644 index 00000000..750e27dd --- /dev/null +++ b/tests/testsuite/rendering.rs @@ -0,0 +1,23 @@ +//! Tests for HTML rendering. + +use crate::prelude::*; + +// Checks that edit-url-template works. +#[test] +fn edit_url_template() { + BookTest::from_dir("rendering/edit_url_template").check_file_contains( + "book/index.html", + "", + ); +} + +// Checks that an alternate `src` setting works with the edit url template. +#[test] +fn edit_url_template_explicit_src() { + BookTest::from_dir("rendering/edit_url_template_explicit_src").check_file_contains( + "book/index.html", + "", + ); +} diff --git a/tests/testsuite/rendering/edit_url_template/book.toml b/tests/testsuite/rendering/edit_url_template/book.toml new file mode 100644 index 00000000..fb942d4a --- /dev/null +++ b/tests/testsuite/rendering/edit_url_template/book.toml @@ -0,0 +1,5 @@ +[book] +title = "edit_url_template" + +[output.html] +edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}" diff --git a/tests/testsuite/rendering/edit_url_template/src/SUMMARY.md b/tests/testsuite/rendering/edit_url_template/src/SUMMARY.md new file mode 100644 index 00000000..3edeb8d3 --- /dev/null +++ b/tests/testsuite/rendering/edit_url_template/src/SUMMARY.md @@ -0,0 +1 @@ +- [Intro](README.md) diff --git a/tests/testsuite/rendering/edit_url_template_explicit_src/book.toml b/tests/testsuite/rendering/edit_url_template_explicit_src/book.toml new file mode 100644 index 00000000..4573d8a9 --- /dev/null +++ b/tests/testsuite/rendering/edit_url_template_explicit_src/book.toml @@ -0,0 +1,6 @@ +[book] +title = "edit_url_template" +src = "src2" + +[output.html] +edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}" diff --git a/tests/testsuite/rendering/edit_url_template_explicit_src/src2/SUMMARY.md b/tests/testsuite/rendering/edit_url_template_explicit_src/src2/SUMMARY.md new file mode 100644 index 00000000..3edeb8d3 --- /dev/null +++ b/tests/testsuite/rendering/edit_url_template_explicit_src/src2/SUMMARY.md @@ -0,0 +1 @@ +- [Intro](README.md)