Merge pull request #2786 from ehuss/read_to_string-prelude

Add read_to_string to the prelude
This commit is contained in:
Eric Huss 2025-08-12 02:31:44 +00:00 committed by GitHub
commit e284eb1c30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 5 deletions

View file

@ -24,6 +24,6 @@ mod theme;
mod toc;
mod prelude {
pub use crate::book_test::BookTest;
pub use crate::book_test::{BookTest, read_to_string};
pub use snapbox::str;
}

View file

@ -7,7 +7,7 @@ use std::path::Path;
fn read_book_index(root: &Path) -> serde_json::Value {
let index = root.join("book/searchindex.js");
let index = std::fs::read_to_string(index).unwrap();
let index = read_to_string(index);
let index =
index.trim_start_matches("window.search = Object.assign(window.search, JSON.parse('");
let index = index.trim_end_matches("'));");

View file

@ -1,11 +1,9 @@
//! Tests for table of contents (sidebar).
use crate::prelude::*;
use anyhow::Context;
use anyhow::Result;
use select::document::Document;
use select::predicate::{Attr, Class, Name, Predicate};
use std::fs;
const TOC_TOP_LEVEL: &[&str] = &[
"1. With Readme",
@ -50,7 +48,7 @@ fn toc_fallback_html() -> Result<Document> {
test.build();
let toc_path = test.dir.join("book").join("toc.html");
let html = fs::read_to_string(toc_path).with_context(|| "Unable to read index.html")?;
let html = read_to_string(toc_path);
Ok(Document::from(html.as_str()))
}