Skip to content

Commit

Permalink
Add an integration test for heading attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed May 28, 2023
1 parent 861197e commit e3be293
Show file tree
Hide file tree
Showing 4 changed files with 431 additions and 117 deletions.
1 change: 1 addition & 0 deletions tests/dummy_book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [Unicode](first/unicode.md)
- [No Headers](first/no-headers.md)
- [Duplicate Headers](first/duplicate-headers.md)
- [Heading Attributes](first/heading-attributes.md)
- [Second Chapter](second.md)
- [Nested Chapter](second/nested.md)

Expand Down
5 changes: 5 additions & 0 deletions tests/dummy_book/src/first/heading-attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Heading Attributes {#attrs}

## Heading with classes {.class1 .class2}

## Heading with id and classes {#both .class1 .class2}
19 changes: 18 additions & 1 deletion tests/rendered_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const TOC_SECOND_LEVEL: &[&str] = &[
"1.5. Unicode",
"1.6. No Headers",
"1.7. Duplicate Headers",
"1.8. Heading Attributes",
"2.1. Nested Chapter",
];

Expand Down Expand Up @@ -766,7 +767,7 @@ mod search {
assert_eq!(docs[&some_section]["body"], "");
assert_eq!(
docs[&summary]["body"],
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode No Headers Duplicate Headers Second Chapter Nested Chapter Conclusion"
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode No Headers Duplicate Headers Heading Attributes Second Chapter Nested Chapter Conclusion"
);
assert_eq!(
docs[&summary]["breadcrumbs"],
Expand Down Expand Up @@ -946,3 +947,19 @@ fn custom_fonts() {
&["fonts.css", "myfont.woff"]
);
}

#[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##"<h1 id="attrs"><a class="header" href="#attrs">Heading Attributes</a></h1>"##,
r##"<h2 id="heading-with-classes" class="class1 class2"><a class="header" href="#heading-with-classes">Heading with classes</a></h2>"##,
r##"<h2 id="both" class="class1 class2"><a class="header" href="#both">Heading with id and classes</a></h2>"##,
];
assert_contains_strings(&contents, summary_strings);
}
Loading

0 comments on commit e3be293

Please sign in to comment.