]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/html/toc/tests.rs
Rollup merge of #61267 - michaelwoerister:update-xlto-table, r=alexcrichton
[rust.git] / src / librustdoc / html / toc / tests.rs
1 use super::{TocBuilder, Toc, 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,
13                                     $name.to_string(),
14                                     "".to_string()),
15                        $name);
16         }
17     }
18     push!(2, "0.1");
19     push!(1, "1");
20     {
21         push!(2, "1.1");
22         {
23             push!(3, "1.1.1");
24             push!(3, "1.1.2");
25         }
26         push!(2, "1.2");
27         {
28             push!(3, "1.2.1");
29             push!(3, "1.2.2");
30         }
31     }
32     push!(1, "2");
33     push!(1, "3");
34     {
35         push!(4, "3.0.0.1");
36         {
37             push!(6, "3.0.0.1.0.1");
38         }
39         push!(4, "3.0.0.2");
40         push!(2, "3.1");
41         {
42             push!(4, "3.1.0.1");
43         }
44     }
45
46     macro_rules! toc {
47         ($(($level: expr, $name: expr, $(($sub: tt))* )),*) => {
48             Toc {
49                 entries: vec![
50                     $(
51                         TocEntry {
52                             level: $level,
53                             name: $name.to_string(),
54                             sec_number: $name.to_string(),
55                             id: "".to_string(),
56                             children: toc!($($sub),*)
57                         }
58                         ),*
59                     ]
60             }
61         }
62     }
63     let expected = toc!(
64         (2, "0.1", ),
65
66         (1, "1",
67          ((2, "1.1", ((3, "1.1.1", )) ((3, "1.1.2", ))))
68          ((2, "1.2", ((3, "1.2.1", )) ((3, "1.2.2", ))))
69          ),
70
71         (1, "2", ),
72
73         (1, "3",
74          ((4, "3.0.0.1", ((6, "3.0.0.1.0.1", ))))
75          ((4, "3.0.0.2", ))
76          ((2, "3.1", ((4, "3.1.0.1", ))))
77          )
78         );
79     assert_eq!(expected, builder.into_toc());
80 }