Skip to content

Commit 477aa63

Browse files
Add tests for {{#title}} include
1 parent e49501f commit 477aa63

File tree

8 files changed

+62
-0
lines changed

8 files changed

+62
-0
lines changed

tests/testsuite/includes.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,37 @@ fn rustdoc_include() {
110110
}</code></pre></pre>
111111
"##]]);
112112
}
113+
114+
/// Checks the behavior of `{{#title}}` include.
115+
#[test]
116+
fn test_title_include() {
117+
BookTest::from_dir("includes/title_handler")
118+
.check_file_contains(
119+
"book/title_from_title_handler.html",
120+
"<title>This is from title handler</title>",
121+
)
122+
.check_file_doesnt_contain(
123+
"book/title_from_title_handler.html",
124+
"<title>Title from summary - 1</title>",
125+
)
126+
.check_file_contains(
127+
"book/title_from_summary.html",
128+
"<title>Title from summary - 2</title>",
129+
);
130+
}
131+
132+
/// Checks the behavior of `{{#title}}` include when a book title is present.
133+
#[test]
134+
fn test_title_include_with_book_title() {
135+
BookTest::from_dir("includes/title_handler_with_book_title")
136+
// Checks that the title from the title handler is used when present
137+
.check_file_contains(
138+
"book/title_from_title_handler.html",
139+
"<title>This is from title handler</title>",
140+
)
141+
// Checks that the title from the summary appended with the book title is used when no title handler is present
142+
.check_file_contains(
143+
"book/title_from_summary.html",
144+
"<title>Title from summary - 2 - Test Book Title</title>",
145+
);
146+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Summary
2+
3+
- [Title from summary - 1](./title_from_title_handler.md)
4+
- [Title from summary - 2](./title_from_summary.md)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This is markdown title - 2
2+
3+
Some content
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This is markdown title - 1
2+
3+
{{#title This is from title handler}}
4+
5+
Some content
6+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[book]
2+
title = "Test Book Title"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Summary
2+
3+
- [Title from summary - 1](./title_from_title_handler.md)
4+
- [Title from summary - 2](./title_from_summary.md)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This is markdown title - 2
2+
3+
Some content
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This is markdown title - 1
2+
3+
{{#title This is from title handler}}
4+
5+
Some content
6+

0 commit comments

Comments
 (0)