]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/html/render/tests.rs
Rollup merge of #82309 - jyn514:rustdocflags, r=Mark-Simulacrum
[rust.git] / src / librustdoc / html / render / tests.rs
1 use super::*;
2
3 #[test]
4 fn test_compare_names() {
5     for &(a, b) in &[
6         ("hello", "world"),
7         ("", "world"),
8         ("123", "hello"),
9         ("123", ""),
10         ("123test", "123"),
11         ("hello", ""),
12         ("hello", "hello"),
13         ("hello123", "hello123"),
14         ("hello123", "hello12"),
15         ("hello12", "hello123"),
16         ("hello01abc", "hello01xyz"),
17         ("hello0abc", "hello0"),
18         ("hello0", "hello0abc"),
19         ("01", "1"),
20     ] {
21         assert_eq!(compare_names(a, b), a.cmp(b), "{:?} - {:?}", a, b);
22     }
23     assert_eq!(compare_names("u8", "u16"), Ordering::Less);
24     assert_eq!(compare_names("u32", "u16"), Ordering::Greater);
25     assert_eq!(compare_names("u8_to_f64", "u16_to_f64"), Ordering::Less);
26     assert_eq!(compare_names("u32_to_f64", "u16_to_f64"), Ordering::Greater);
27     assert_eq!(compare_names("u16_to_f64", "u16_to_f64"), Ordering::Equal);
28     assert_eq!(compare_names("u16_to_f32", "u16_to_f64"), Ordering::Less);
29 }
30
31 #[test]
32 fn test_name_sorting() {
33     let names = [
34         "Apple", "Banana", "Fruit", "Fruit0", "Fruit00", "Fruit01", "Fruit1", "Fruit02", "Fruit2",
35         "Fruit20", "Fruit30x", "Fruit100", "Pear",
36     ];
37     let mut sorted = names.to_owned();
38     sorted.sort_by(|&l, r| compare_names(l, r));
39     assert_eq!(names, sorted);
40 }
41
42 #[test]
43 fn test_all_types_prints_header_once() {
44     // Regression test for #82477
45     let all_types = AllTypes::new();
46
47     let mut buffer = Buffer::new();
48     all_types.print(&mut buffer);
49
50     assert_eq!(1, buffer.into_inner().matches("List of all items").count());
51 }