From c2c37705e7af909797ebd42327bda379802724c1 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 22 Apr 2025 11:12:01 -0700 Subject: [PATCH] Migrate custom fonts.css to BookTest --- tests/rendered_output.rs | 14 ------------ tests/testsuite/theme.rs | 22 +++++++++++++++++++ .../testsuite/theme/fonts_css/src/SUMMARY.md | 1 + .../theme/fonts_css/theme/fonts/fonts.css | 1 + .../theme/fonts_css/theme/fonts/myfont.woff | 0 5 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 tests/testsuite/theme/fonts_css/src/SUMMARY.md create mode 100644 tests/testsuite/theme/fonts_css/theme/fonts/fonts.css create mode 100644 tests/testsuite/theme/fonts_css/theme/fonts/myfont.woff diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index f9b4c48e..20a91825 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -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(); diff --git a/tests/testsuite/theme.rs b/tests/testsuite/theme.rs index c552d452..9cab6e57 100644 --- a/tests/testsuite/theme.rs +++ b/tests/testsuite/theme.rs @@ -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 +"#]], + ); +} diff --git a/tests/testsuite/theme/fonts_css/src/SUMMARY.md b/tests/testsuite/theme/fonts_css/src/SUMMARY.md new file mode 100644 index 00000000..510ba886 --- /dev/null +++ b/tests/testsuite/theme/fonts_css/src/SUMMARY.md @@ -0,0 +1 @@ +- [With Fonts](index.md) diff --git a/tests/testsuite/theme/fonts_css/theme/fonts/fonts.css b/tests/testsuite/theme/fonts_css/theme/fonts/fonts.css new file mode 100644 index 00000000..b94b7f50 --- /dev/null +++ b/tests/testsuite/theme/fonts_css/theme/fonts/fonts.css @@ -0,0 +1 @@ +/*custom*/ diff --git a/tests/testsuite/theme/fonts_css/theme/fonts/myfont.woff b/tests/testsuite/theme/fonts_css/theme/fonts/myfont.woff new file mode 100644 index 00000000..e69de29b