Migrate custom fonts.css to BookTest

This commit is contained in:
Eric Huss 2025-04-22 11:12:01 -07:00
parent 5f227613aa
commit c2c37705e7
5 changed files with 24 additions and 14 deletions

View file

@ -323,20 +323,6 @@ fn custom_fonts() {
contents.contains("fonts/fonts.css")
};
// Mixed with copy-fonts=true
// Should ignore the copy-fonts setting since the user has provided their own fonts.css.
let temp = TempFileBuilder::new().prefix("mdbook").tempdir().unwrap();
let p = temp.path();
MDBook::init(p).build().unwrap();
write_file(&p.join("theme/fonts"), "fonts.css", b"/*custom*/").unwrap();
write_file(&p.join("theme/fonts"), "myfont.woff", b"").unwrap();
MDBook::load(p).unwrap().build().unwrap();
assert!(has_fonts_css(p));
assert_eq!(
actual_files(&p.join("book/fonts")),
["fonts.css", "myfont.woff"]
);
// copy-fonts=false, no theme
// This should generate a deprecation warning.
let temp = TempFileBuilder::new().prefix("mdbook").tempdir().unwrap();

View file

@ -115,3 +115,25 @@ book/fonts/source-code-pro-v11-all-charsets-500.woff2
"#]],
);
}
// Custom fonts.css.
#[test]
fn fonts_css() {
BookTest::from_dir("theme/fonts_css")
.check_file_contains("book/index.html", "fonts/fonts.css")
.check_file(
"book/fonts/fonts.css",
str![[r#"
/*custom*/
"#]],
)
.check_file("book/fonts/myfont.woff", str![[""]])
.check_file_list(
"book/fonts",
str![[r#"
book/fonts/fonts.css
book/fonts/myfont.woff
"#]],
);
}

View file

@ -0,0 +1 @@
- [With Fonts](index.md)

View file

@ -0,0 +1 @@
/*custom*/