2025-04-22 11:05:48 -07:00
|
|
|
//! Tests for theme handling.
|
|
|
|
|
|
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
|
|
// Checks what happens if the theme directory is missing.
|
|
|
|
|
#[test]
|
|
|
|
|
fn missing_theme() {
|
2025-09-12 06:13:45 -07:00
|
|
|
BookTest::from_dir("theme/missing_theme").run("build", |cmd| {
|
|
|
|
|
cmd.expect_failure().expect_stderr(str![[r#"
|
|
|
|
|
INFO Book building has started
|
|
|
|
|
INFO Running the html backend
|
|
|
|
|
ERROR Rendering failed
|
|
|
|
|
[TAB]Caused by: theme dir [ROOT]/./non-existent-directory does not exist
|
2025-04-22 11:05:48 -07:00
|
|
|
|
|
|
|
|
"#]]);
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-04-22 11:06:48 -07:00
|
|
|
|
|
|
|
|
// Checks what happens if the theme directory is empty.
|
|
|
|
|
#[test]
|
|
|
|
|
fn empty_theme() {
|
|
|
|
|
BookTest::from_dir("theme/empty_theme").run("build", |cmd| {
|
|
|
|
|
std::fs::create_dir(cmd.dir.join("theme")).unwrap();
|
|
|
|
|
cmd.expect_stderr(str![[r#"
|
2025-09-12 06:13:45 -07:00
|
|
|
INFO Book building has started
|
|
|
|
|
INFO Running the html backend
|
|
|
|
|
INFO HTML book written to `[ROOT]/book`
|
2025-04-22 11:06:48 -07:00
|
|
|
|
|
|
|
|
"#]]);
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-04-22 11:08:23 -07:00
|
|
|
|
|
|
|
|
// Checks overriding index.hbs.
|
|
|
|
|
#[test]
|
|
|
|
|
fn override_index() {
|
|
|
|
|
BookTest::from_dir("theme/override_index").check_file(
|
|
|
|
|
"book/index.html",
|
|
|
|
|
str![[r#"
|
|
|
|
|
This is a modified index.hbs!
|
|
|
|
|
|
|
|
|
|
"#]],
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-04-22 11:09:20 -07:00
|
|
|
|
|
|
|
|
// After building, what are the default set of fonts?
|
|
|
|
|
#[test]
|
|
|
|
|
fn default_fonts() {
|
|
|
|
|
BookTest::init(|_| {})
|
2025-08-26 15:58:18 -07:00
|
|
|
.check_file_contains("book/index.html", "fonts/fonts-[..].css")
|
2025-04-22 11:09:20 -07:00
|
|
|
.check_file_list(
|
|
|
|
|
"book/fonts",
|
|
|
|
|
str![[r#"
|
|
|
|
|
book/fonts/OPEN-SANS-LICENSE.txt
|
|
|
|
|
book/fonts/SOURCE-CODE-PRO-LICENSE.txt
|
2025-08-26 15:58:18 -07:00
|
|
|
book/fonts/fonts-[..].css
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-300-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-300italic-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-600-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-600italic-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-700-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-700italic-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-800-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-800italic-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-italic-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-regular-[..].woff2
|
|
|
|
|
book/fonts/source-code-pro-v11-all-charsets-500-[..].woff2
|
2025-04-22 11:09:20 -07:00
|
|
|
"#]],
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-04-22 11:10:20 -07:00
|
|
|
|
|
|
|
|
// When the theme is initialized, what does the fonts list look like?
|
|
|
|
|
#[test]
|
|
|
|
|
fn theme_fonts_copied() {
|
|
|
|
|
BookTest::init(|bb| {
|
|
|
|
|
bb.copy_theme(true);
|
|
|
|
|
})
|
2025-08-26 15:58:18 -07:00
|
|
|
.check_file_contains("book/index.html", "fonts/fonts-[..].css")
|
2025-04-22 11:10:20 -07:00
|
|
|
.check_file_list(
|
|
|
|
|
"theme/fonts",
|
|
|
|
|
str![[r#"
|
|
|
|
|
theme/fonts/OPEN-SANS-LICENSE.txt
|
|
|
|
|
theme/fonts/SOURCE-CODE-PRO-LICENSE.txt
|
|
|
|
|
theme/fonts/fonts.css
|
|
|
|
|
theme/fonts/open-sans-v17-all-charsets-300.woff2
|
|
|
|
|
theme/fonts/open-sans-v17-all-charsets-300italic.woff2
|
|
|
|
|
theme/fonts/open-sans-v17-all-charsets-600.woff2
|
|
|
|
|
theme/fonts/open-sans-v17-all-charsets-600italic.woff2
|
|
|
|
|
theme/fonts/open-sans-v17-all-charsets-700.woff2
|
|
|
|
|
theme/fonts/open-sans-v17-all-charsets-700italic.woff2
|
|
|
|
|
theme/fonts/open-sans-v17-all-charsets-800.woff2
|
|
|
|
|
theme/fonts/open-sans-v17-all-charsets-800italic.woff2
|
|
|
|
|
theme/fonts/open-sans-v17-all-charsets-italic.woff2
|
|
|
|
|
theme/fonts/open-sans-v17-all-charsets-regular.woff2
|
|
|
|
|
theme/fonts/source-code-pro-v11-all-charsets-500.woff2
|
|
|
|
|
"#]],
|
|
|
|
|
)
|
2025-08-26 15:58:18 -07:00
|
|
|
// Note that license files get hashed, which is not like the behavior when
|
|
|
|
|
// the theme directory is empty. It kinda makes sense, but is weird.
|
2025-04-22 11:10:20 -07:00
|
|
|
.check_file_list(
|
|
|
|
|
"book/fonts",
|
|
|
|
|
str![[r#"
|
2025-08-26 15:58:18 -07:00
|
|
|
book/fonts/OPEN-SANS-LICENSE-[..].txt
|
|
|
|
|
book/fonts/SOURCE-CODE-PRO-LICENSE-[..].txt
|
|
|
|
|
book/fonts/fonts-[..].css
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-300-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-300italic-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-600-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-600italic-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-700-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-700italic-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-800-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-800italic-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-italic-[..].woff2
|
|
|
|
|
book/fonts/open-sans-v17-all-charsets-regular-[..].woff2
|
|
|
|
|
book/fonts/source-code-pro-v11-all-charsets-500-[..].woff2
|
2025-04-22 11:10:20 -07:00
|
|
|
"#]],
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-04-22 11:12:01 -07:00
|
|
|
|
|
|
|
|
// Custom fonts.css.
|
|
|
|
|
#[test]
|
|
|
|
|
fn fonts_css() {
|
|
|
|
|
BookTest::from_dir("theme/fonts_css")
|
2025-08-26 15:58:18 -07:00
|
|
|
.check_file_contains("book/index.html", "fonts/fonts-[..].css")
|
2025-04-22 11:12:01 -07:00
|
|
|
.check_file(
|
2025-08-26 15:58:18 -07:00
|
|
|
"book/fonts/fonts-*.css",
|
2025-04-22 11:12:01 -07:00
|
|
|
str![[r#"
|
|
|
|
|
/*custom*/
|
|
|
|
|
|
|
|
|
|
"#]],
|
|
|
|
|
)
|
2025-08-26 15:58:18 -07:00
|
|
|
.check_file("book/fonts/myfont-*.woff", str![[""]])
|
2025-04-22 11:12:01 -07:00
|
|
|
.check_file_list(
|
|
|
|
|
"book/fonts",
|
|
|
|
|
str![[r#"
|
2025-08-26 15:58:18 -07:00
|
|
|
book/fonts/fonts-[..].css
|
|
|
|
|
book/fonts/myfont-[..].woff
|
2025-04-22 11:12:01 -07:00
|
|
|
"#]],
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-04-22 11:12:30 -07:00
|
|
|
|
2025-08-12 17:55:41 -07:00
|
|
|
// Empty fonts.css should not copy the default fonts.
|
2025-04-22 11:12:30 -07:00
|
|
|
#[test]
|
2025-08-12 17:55:41 -07:00
|
|
|
fn empty_fonts_css() {
|
|
|
|
|
BookTest::from_dir("theme/empty_fonts_css")
|
2025-04-22 11:12:30 -07:00
|
|
|
.run("build", |cmd| {
|
|
|
|
|
cmd.expect_stderr(str![[r#"
|
2025-09-12 06:13:45 -07:00
|
|
|
INFO Book building has started
|
|
|
|
|
INFO Running the html backend
|
|
|
|
|
INFO HTML book written to `[ROOT]/book`
|
2025-04-22 11:12:30 -07:00
|
|
|
|
|
|
|
|
"#]]);
|
|
|
|
|
})
|
2025-08-12 17:55:41 -07:00
|
|
|
.check_file_contains("book/index.html", "fonts.css")
|
2025-04-22 11:13:03 -07:00
|
|
|
.check_file_list("book/fonts", str![[""]]);
|
|
|
|
|
}
|
2025-04-22 11:13:39 -07:00
|
|
|
|
2025-08-12 17:55:41 -07:00
|
|
|
// Custom fonts.css file shouldn't copy default fonts.
|
2025-04-22 11:13:39 -07:00
|
|
|
#[test]
|
2025-08-12 17:55:41 -07:00
|
|
|
fn custom_fonts_css() {
|
|
|
|
|
BookTest::from_dir("theme/custom_fonts_css")
|
2025-04-22 11:13:39 -07:00
|
|
|
.run("build", |cmd| {
|
|
|
|
|
cmd.expect_stderr(str![[r#"
|
2025-09-12 06:13:45 -07:00
|
|
|
INFO Book building has started
|
|
|
|
|
INFO Running the html backend
|
|
|
|
|
INFO HTML book written to `[ROOT]/book`
|
2025-04-22 11:13:39 -07:00
|
|
|
|
|
|
|
|
"#]]);
|
|
|
|
|
})
|
2025-08-26 15:58:18 -07:00
|
|
|
.check_file_contains("book/index.html", "fonts-[..].css")
|
2025-04-22 11:13:39 -07:00
|
|
|
.check_file_list(
|
|
|
|
|
"book/fonts",
|
|
|
|
|
str![[r#"
|
2025-08-26 15:58:18 -07:00
|
|
|
book/fonts/fonts-[..].css
|
|
|
|
|
book/fonts/myfont-[..].woff
|
2025-04-22 11:13:39 -07:00
|
|
|
"#]],
|
|
|
|
|
);
|
|
|
|
|
}
|