1 use std::cmp::Ordering;
3 use super::print_item::compare_names;
4 use super::{AllTypes, Buffer};
7 fn test_compare_names() {
16 ("hello123", "hello123"),
17 ("hello123", "hello12"),
18 ("hello12", "hello123"),
19 ("hello01abc", "hello01xyz"),
20 ("hello0abc", "hello0"),
21 ("hello0", "hello0abc"),
24 assert_eq!(compare_names(a, b), a.cmp(b), "{:?} - {:?}", a, b);
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);
35 fn test_name_sorting() {
37 "Apple", "Banana", "Fruit", "Fruit0", "Fruit00", "Fruit01", "Fruit1", "Fruit02", "Fruit2",
38 "Fruit20", "Fruit30x", "Fruit100", "Pear",
40 let mut sorted = names.to_owned();
41 sorted.sort_by(|&l, r| compare_names(l, r));
42 assert_eq!(names, sorted);
46 fn test_all_types_prints_header_once() {
47 // Regression test for #82477
48 let all_types = AllTypes::new();
50 let mut buffer = Buffer::new();
51 all_types.print(&mut buffer);
53 assert_eq!(1, buffer.into_inner().matches("List of all items").count());