Debian Codegraph @

tests/testsuite/theme.rs

raw
1 //! Tests for theme handling.
2
3 use crate::prelude::*;
4
5 // Checks what happens if the theme directory is missing.
6 #[test]
7 fn missing_theme() {
8 BookTest::from_dir("theme/missing_theme").run("build", |cmd| {
9 cmd.expect_failure().expect_stderr(str![[r#"
10 INFO Book building has started
11 INFO Running the html backend
12 ERROR Rendering failed
13 [TAB]Caused by: theme dir [ROOT]/./non-existent-directory does not exist
14
15 "#]]);
16 });
17 }
18
19 // Checks what happens if the theme directory is empty.
20 #[test]
21 fn empty_theme() {
22 BookTest::from_dir("theme/empty_theme").run("build", |cmd| {
23 std::fs::create_dir(cmd.dir.join("theme")).unwrap();
24 cmd.expect_stderr(str![[r#"
25 INFO Book building has started
26 INFO Running the html backend
27 INFO HTML book written to `[ROOT]/book`
28
29 "#]]);
30 });
31 }
32
33 // Checks overriding index.hbs.
34 #[test]
35 fn override_index() {
36 BookTest::from_dir("theme/override_index").check_file(
37 "book/index.html",
38 str![[r#"
39 This is a modified index.hbs!
40
41 "#]],
42 );
43 }
44
45 // After building, what are the default set of fonts?
46 #[test]
47 fn default_fonts() {
48 BookTest::init(|_| {})
49 .check_file_contains("book/index.html", "fonts/fonts-[..].css")
50 .check_file_list(
51 "book/fonts",
52 str![[r#"
53 book/fonts/OPEN-SANS-LICENSE.txt
54 book/fonts/SOURCE-CODE-PRO-LICENSE.txt
55 book/fonts/fonts-[..].css
56 book/fonts/open-sans-v17-all-charsets-300-[..].woff2
57 book/fonts/open-sans-v17-all-charsets-300italic-[..].woff2
58 book/fonts/open-sans-v17-all-charsets-600-[..].woff2
59 book/fonts/open-sans-v17-all-charsets-600italic-[..].woff2
60 book/fonts/open-sans-v17-all-charsets-700-[..].woff2
61 book/fonts/open-sans-v17-all-charsets-700italic-[..].woff2
62 book/fonts/open-sans-v17-all-charsets-800-[..].woff2
63 book/fonts/open-sans-v17-all-charsets-800italic-[..].woff2
64 book/fonts/open-sans-v17-all-charsets-italic-[..].woff2
65 book/fonts/open-sans-v17-all-charsets-regular-[..].woff2
66 book/fonts/source-code-pro-v11-all-charsets-500-[..].woff2
67 "#]],
68 );
69 }
70
71 // When the theme is initialized, what does the fonts list look like?
72 #[test]
73 fn theme_fonts_copied() {
74 BookTest::init(|bb| {
75 bb.copy_theme(true);
76 })
77 .check_file_contains("book/index.html", "fonts/fonts-[..].css")
78 .check_file_list(
79 "theme/fonts",
80 str![[r#"
81 theme/fonts/OPEN-SANS-LICENSE.txt
82 theme/fonts/SOURCE-CODE-PRO-LICENSE.txt
83 theme/fonts/fonts.css
84 theme/fonts/open-sans-v17-all-charsets-300.woff2
85 theme/fonts/open-sans-v17-all-charsets-300italic.woff2
86 theme/fonts/open-sans-v17-all-charsets-600.woff2
87 theme/fonts/open-sans-v17-all-charsets-600italic.woff2
88 theme/fonts/open-sans-v17-all-charsets-700.woff2
89 theme/fonts/open-sans-v17-all-charsets-700italic.woff2
90 theme/fonts/open-sans-v17-all-charsets-800.woff2
91 theme/fonts/open-sans-v17-all-charsets-800italic.woff2
92 theme/fonts/open-sans-v17-all-charsets-italic.woff2
93 theme/fonts/open-sans-v17-all-charsets-regular.woff2
94 theme/fonts/source-code-pro-v11-all-charsets-500.woff2
95 "#]],
96 )
97 // Note that license files get hashed, which is not like the behavior when
98 // the theme directory is empty. It kinda makes sense, but is weird.
99 .check_file_list(
100 "book/fonts",
101 str![[r#"
102 book/fonts/OPEN-SANS-LICENSE-[..].txt
103 book/fonts/SOURCE-CODE-PRO-LICENSE-[..].txt
104 book/fonts/fonts-[..].css
105 book/fonts/open-sans-v17-all-charsets-300-[..].woff2
106 book/fonts/open-sans-v17-all-charsets-300italic-[..].woff2
107 book/fonts/open-sans-v17-all-charsets-600-[..].woff2
108 book/fonts/open-sans-v17-all-charsets-600italic-[..].woff2
109 book/fonts/open-sans-v17-all-charsets-700-[..].woff2
110 book/fonts/open-sans-v17-all-charsets-700italic-[..].woff2
111 book/fonts/open-sans-v17-all-charsets-800-[..].woff2
112 book/fonts/open-sans-v17-all-charsets-800italic-[..].woff2
113 book/fonts/open-sans-v17-all-charsets-italic-[..].woff2
114 book/fonts/open-sans-v17-all-charsets-regular-[..].woff2
115 book/fonts/source-code-pro-v11-all-charsets-500-[..].woff2
116 "#]],
117 );
118 }
119
120 // Custom fonts.css.
121 #[test]
122 fn fonts_css() {
123 BookTest::from_dir("theme/fonts_css")
124 .check_file_contains("book/index.html", "fonts/fonts-[..].css")
125 .check_file(
126 "book/fonts/fonts-*.css",
127 str![[r#"
128 /*custom*/
129
130 "#]],
131 )
132 .check_file("book/fonts/myfont-*.woff", str![[""]])
133 .check_file_list(
134 "book/fonts",
135 str![[r#"
136 book/fonts/fonts-[..].css
137 book/fonts/myfont-[..].woff
138 "#]],
139 );
140 }
141
142 // Empty fonts.css should not copy the default fonts.
143 #[test]
144 fn empty_fonts_css() {
145 BookTest::from_dir("theme/empty_fonts_css")
146 .run("build", |cmd| {
147 cmd.expect_stderr(str![[r#"
148 INFO Book building has started
149 INFO Running the html backend
150 INFO HTML book written to `[ROOT]/book`
151
152 "#]]);
153 })
154 .check_file_contains("book/index.html", "fonts.css")
155 .check_file_list("book/fonts", str![[""]]);
156 }
157
158 // Custom fonts.css file shouldn't copy default fonts.
159 #[test]
160 fn custom_fonts_css() {
161 BookTest::from_dir("theme/custom_fonts_css")
162 .run("build", |cmd| {
163 cmd.expect_stderr(str![[r#"
164 INFO Book building has started
165 INFO Running the html backend
166 INFO HTML book written to `[ROOT]/book`
167
168 "#]]);
169 })
170 .check_file_contains("book/index.html", "fonts-[..].css")
171 .check_file_list(
172 "book/fonts",
173 str![[r#"
174 book/fonts/fonts-[..].css
175 book/fonts/myfont-[..].woff
176 "#]],
177 );
178 }