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