Migrate check_first_toc_level to BookTest

This commit is contained in:
Eric Huss 2025-04-22 11:19:21 -07:00
parent 14d412b279
commit efc5ee4449
2 changed files with 31 additions and 23 deletions

View file

@ -169,29 +169,6 @@ fn toc_fallback_html() -> Result<Document> {
Ok(Document::from(html.as_str()))
}
#[test]
fn check_first_toc_level() {
let doc = toc_js_html().unwrap();
let mut should_be = Vec::from(TOC_TOP_LEVEL);
should_be.extend(TOC_SECOND_LEVEL);
should_be.sort_unstable();
let pred = descendants!(
Class("chapter"),
Name("li"),
Name("a").and(Class("toggle").not())
);
let mut children: Vec<_> = doc
.find(pred)
.map(|elem| elem.text().trim().to_string())
.collect();
children.sort();
assert_eq!(children, should_be);
}
#[test]
fn check_spacers() {
let doc = toc_js_html().unwrap();

View file

@ -4,6 +4,14 @@ use crate::prelude::*;
use select::document::Document;
use select::predicate::{Class, Name, Predicate};
const TOC_TOP_LEVEL: &[&str] = &[
"1. With Readme",
"3. Deep Nest 1",
"Prefix 1",
"Prefix 2",
"Suffix 1",
"Suffix 2",
];
const TOC_SECOND_LEVEL: &[&str] = &[
"1.1. Nested Index",
"1.2. Nested two",
@ -53,3 +61,26 @@ fn check_second_toc_level() {
assert_eq!(children_of_children, should_be);
}
#[test]
fn check_first_toc_level() {
let doc = toc_js_html();
let mut should_be = Vec::from(TOC_TOP_LEVEL);
should_be.extend(TOC_SECOND_LEVEL);
should_be.sort_unstable();
let pred = descendants!(
Class("chapter"),
Name("li"),
Name("a").and(Class("toggle").not())
);
let mut children: Vec<_> = doc
.find(pred)
.map(|elem| elem.text().trim().to_string())
.collect();
children.sort();
assert_eq!(children, should_be);
}