Migrate edit-url-template tests to BookTest

This commit is contained in:
Eric Huss 2025-04-22 08:54:31 -07:00
parent 2f10831a80
commit d23bdaa527
7 changed files with 38 additions and 52 deletions

View file

@ -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() {

View file

@ -14,6 +14,7 @@ mod preprocessor;
mod print;
mod redirects;
mod renderer;
mod rendering;
mod prelude {
pub use crate::book_test::BookTest;

View file

@ -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",
"<a href=\"https://github.com/rust-lang/mdBook/edit/master/guide/src/README.md\" \
title=\"Suggest an edit\" aria-label=\"Suggest an edit\">",
);
}
// 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",
"<a href=\"https://github.com/rust-lang/mdBook/edit/master/guide/src2/README.md\" \
title=\"Suggest an edit\" aria-label=\"Suggest an edit\">",
);
}

View file

@ -0,0 +1,5 @@
[book]
title = "edit_url_template"
[output.html]
edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}"

View file

@ -0,0 +1 @@
- [Intro](README.md)

View file

@ -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}"

View file

@ -0,0 +1 @@
- [Intro](README.md)