Debian Codegraph @

tests/testsuite/includes.rs

raw
1 //! Tests for include preprocessor.
2
3 use crate::prelude::*;
4
5 // Basic test for #include.
6 #[test]
7 fn include() {
8 BookTest::from_dir("includes/all_includes")
9 .check_main_file(
10 "book/includes.html",
11 str![[r##"
12 <h1 id="basic-includes"><a class="header" href="#basic-includes">Basic Includes</a></h1>
13 <h2 id="sample"><a class="header" href="#sample">Sample</a></h2>
14 <p>This is a sample include.</p>
15 "##]],
16 )
17 .check_main_file(
18 "book/relative/includes.html",
19 str![[r##"
20 <h1 id="relative-includes"><a class="header" href="#relative-includes">Relative Includes</a></h1>
21 <h2 id="sample"><a class="header" href="#sample">Sample</a></h2>
22 <p>This is a sample include.</p>
23 "##]],
24 );
25 }
26
27 // Checks for anchored includes.
28 #[test]
29 fn anchored_include() {
30 BookTest::from_dir("includes/all_includes").check_main_file(
31 "book/anchors.html",
32 str![[r##"
33 <h1 id="include-anchors"><a class="header" href="#include-anchors">Include Anchors</a></h1>
34 <pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
35 </span><span class="boring">fn main() {
36 </span>let x = 1;
37 <span class="boring">}</span></code></pre>
38 "##]],
39 );
40 }
41
42 // Checks behavior of recursive include.
43 #[test]
44 fn recursive_include() {
45 BookTest::from_dir("includes/all_includes")
46 .run("build", |cmd| {
47 cmd.expect_stderr(str![[r#"
48 INFO Book building has started
49 ERROR Stack depth exceeded in recursive.md. Check for cyclic includes
50 INFO Running the html backend
51 INFO HTML book written to `[ROOT]/book`
52
53 "#]]);
54 })
55 .check_main_file(
56 "book/recursive.html",
57 str![[r#"
58 <p>Around the world, around the world
59 Around the world, around the world
60 Around the world, around the world
61 Around the world, around the world
62 Around the world, around the world
63 Around the world, around the world
64 Around the world, around the world
65 Around the world, around the world
66 Around the world, around the world
67 Around the world, around the world
68 Around the world, around the world</p>
69 "#]],
70 );
71 }
72
73 // Checks the behavior of `{{#playground}}` include.
74 #[test]
75 fn playground_include() {
76 BookTest::from_dir("includes/all_includes")
77 .check_main_file("book/playground.html",
78 str![[r##"
79 <h1 id="playground-includes"><a class="header" href="#playground-includes">Playground Includes</a></h1>
80 <pre class="playground"><code class="language-rust">fn main() {
81 println!("Hello World!");
82 <span class="boring">
83 </span><span class="boring"> // You can even hide lines! :D
84 </span><span class="boring"> println!("I am hidden! Expand the code snippet to see me");
85 </span>}</code></pre>
86 "##]]);
87 }
88
89 // Checks the behavior of `{{#rustdoc_include}}`.
90 #[test]
91 fn rustdoc_include() {
92 BookTest::from_dir("includes/all_includes")
93 .check_main_file("book/rustdoc.html",
94 str![[r##"
95 <h1 id="rustdoc-includes"><a class="header" href="#rustdoc-includes">Rustdoc Includes</a></h1>
96 <h2 id="rustdoc-include-adds-the-rest-of-the-file-as-hidden"><a class="header" href="#rustdoc-include-adds-the-rest-of-the-file-as-hidden">Rustdoc include adds the rest of the file as hidden</a></h2>
97 <pre class="playground"><code class="language-rust"><span class="boring">fn some_function() {
98 </span><span class="boring"> println!("some function");
99 </span><span class="boring">}
100 </span><span class="boring">
101 </span>fn main() {
102 some_function();
103 }</code></pre>
104 <h2 id="rustdoc-include-works-with-anchors-too"><a class="header" href="#rustdoc-include-works-with-anchors-too">Rustdoc include works with anchors too</a></h2>
105 <pre class="playground"><code class="language-rust"><span class="boring">fn some_other_function() {
106 </span><span class="boring"> println!("unused anchor");
107 </span><span class="boring">}
108 </span><span class="boring">
109 </span>fn main() {
110 some_other_function();
111 }</code></pre>
112 "##]]);
113 }