]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/html/toc/tests.rs
Merge commit '5988bbd24aa87732bfa1d111ba00bcdaa22c481a' into sync_cg_clif-2020-11-27
[rust.git] / src / librustdoc / html / toc / tests.rs
1 use super::{Toc, TocBuilder, TocEntry};
2
3 #[test]
4 fn builder_smoke() {
5     let mut builder = TocBuilder::new();
6
7     // this is purposely not using a fancy macro like below so
8     // that we're sure that this is doing the correct thing, and
9     // there's been no macro mistake.
10     macro_rules! push {
11         ($level: expr, $name: expr) => {
12             assert_eq!(builder.push($level, $name.to_string(), "".to_string()), $name);
13         };
14     }
15     push!(2, "0.1");
16     push!(1, "1");
17     {
18         push!(2, "1.1");
19         {
20             push!(3, "1.1.1");
21             push!(3, "1.1.2");
22         }
23         push!(2, "1.2");
24         {
25             push!(3, "1.2.1");
26             push!(3, "1.2.2");
27         }
28     }
29     push!(1, "2");
30     push!(1, "3");
31     {
32         push!(4, "3.0.0.1");
33         {
34             push!(6, "3.0.0.1.0.1");
35         }
36         push!(4, "3.0.0.2");
37         push!(2, "3.1");
38         {
39             push!(4, "3.1.0.1");
40         }
41     }
42
43     macro_rules! toc {
44         ($(($level: expr, $name: expr, $(($sub: tt))* )),*) => {
45             Toc {
46                 entries: vec![
47                     $(
48                         TocEntry {
49                             level: $level,
50                             name: $name.to_string(),
51                             sec_number: $name.to_string(),
52                             id: "".to_string(),
53                             children: toc!($($sub),*)
54                         }
55                         ),*
56                     ]
57             }
58         }
59     }
60     let expected = toc!(
61         (2, "0.1",),
62         (
63             1,
64             "1",
65             ((2, "1.1", ((3, "1.1.1",))((3, "1.1.2",))))((
66                 2,
67                 "1.2",
68                 ((3, "1.2.1",))((3, "1.2.2",))
69             ))
70         ),
71         (1, "2",),
72         (
73             1,
74             "3",
75             ((4, "3.0.0.1", ((6, "3.0.0.1.0.1",))))((4, "3.0.0.2",))((2, "3.1", ((4, "3.1.0.1",))))
76         )
77     );
78     assert_eq!(expected, builder.into_toc());
79 }