From 6904653a824e296ae1a239a41f7ab38966cec505 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 22 Apr 2025 11:30:11 -0700 Subject: [PATCH] Migrate custom_header_attributes to BookTest --- tests/rendered_output.rs | 16 ---------------- tests/testsuite/markdown.rs | 11 +++++++++++ .../markdown/custom_header_attributes/book.toml | 2 ++ .../custom_header_attributes/src/SUMMARY.md | 3 +++ .../src/custom_header_attributes.md | 5 +++++ 5 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 tests/testsuite/markdown/custom_header_attributes/book.toml create mode 100644 tests/testsuite/markdown/custom_header_attributes/src/SUMMARY.md create mode 100644 tests/testsuite/markdown/custom_header_attributes/src/custom_header_attributes.md diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 5da167c0..a231bf16 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -829,22 +829,6 @@ fn custom_fonts() { ); } -#[test] -fn custom_header_attributes() { - let temp = DummyBook::new().build().unwrap(); - let md = MDBook::load(temp.path()).unwrap(); - md.build().unwrap(); - - let contents = temp.path().join("book/first/heading-attributes.html"); - - let summary_strings = &[ - r##"

Heading Attributes

"##, - r##"

Heading with classes

"##, - r##"

Heading with id and classes

"##, - ]; - assert_contains_strings(&contents, summary_strings); -} - #[test] fn with_no_source_path() { // Test for a regression where search would fail if source_path is None. diff --git a/tests/testsuite/markdown.rs b/tests/testsuite/markdown.rs index 18c9daf7..61317e6b 100644 --- a/tests/testsuite/markdown.rs +++ b/tests/testsuite/markdown.rs @@ -2,6 +2,17 @@ use crate::prelude::*; +// Checks custom header id and classes. +#[test] +fn custom_header_attributes() { + BookTest::from_dir("markdown/custom_header_attributes") + .check_main_file("book/custom_header_attributes.html", str![[r##" +

Heading Attributes

+

Heading with classes

+

Heading with id and classes

+"##]]); +} + // Test for a variety of footnote renderings. #[test] fn footnotes() { diff --git a/tests/testsuite/markdown/custom_header_attributes/book.toml b/tests/testsuite/markdown/custom_header_attributes/book.toml new file mode 100644 index 00000000..3c4b914b --- /dev/null +++ b/tests/testsuite/markdown/custom_header_attributes/book.toml @@ -0,0 +1,2 @@ +[book] +title = "custom_header_attributes" diff --git a/tests/testsuite/markdown/custom_header_attributes/src/SUMMARY.md b/tests/testsuite/markdown/custom_header_attributes/src/SUMMARY.md new file mode 100644 index 00000000..56dd8b10 --- /dev/null +++ b/tests/testsuite/markdown/custom_header_attributes/src/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + +- [Heading Attributes](./custom_header_attributes.md) diff --git a/tests/testsuite/markdown/custom_header_attributes/src/custom_header_attributes.md b/tests/testsuite/markdown/custom_header_attributes/src/custom_header_attributes.md new file mode 100644 index 00000000..a09a22b6 --- /dev/null +++ b/tests/testsuite/markdown/custom_header_attributes/src/custom_header_attributes.md @@ -0,0 +1,5 @@ +# Heading Attributes {#attrs} + +## Heading with classes {.class1 .class2} + +## Heading with id and classes {#both .class1 .class2}