]> git.proxmox.com Git - rustc.git/blob - src/libcore/tests/fmt/mod.rs
New upstream version 1.34.2+dfsg1
[rustc.git] / src / libcore / tests / fmt / mod.rs
1 mod builders;
2 mod float;
3 mod num;
4
5 #[test]
6 #[cfg(not(miri))] // Miri cannot print pointers
7 fn test_format_flags() {
8 // No residual flags left by pointer formatting
9 let p = "".as_ptr();
10 assert_eq!(format!("{:p} {:x}", p, 16), format!("{:p} 10", p));
11
12 assert_eq!(format!("{: >3}", 'a'), " a");
13 }
14
15 #[test]
16 #[cfg(not(miri))] // Miri cannot print pointers
17 fn test_pointer_formats_data_pointer() {
18 let b: &[u8] = b"";
19 let s: &str = "";
20 assert_eq!(format!("{:p}", s), format!("{:p}", s.as_ptr()));
21 assert_eq!(format!("{:p}", b), format!("{:p}", b.as_ptr()));
22 }
23
24 #[test]
25 fn test_estimated_capacity() {
26 assert_eq!(format_args!("").estimated_capacity(), 0);
27 assert_eq!(format_args!("{}", "").estimated_capacity(), 0);
28 assert_eq!(format_args!("Hello").estimated_capacity(), 5);
29 assert_eq!(format_args!("Hello, {}!", "").estimated_capacity(), 16);
30 assert_eq!(format_args!("{}, hello!", "World").estimated_capacity(), 0);
31 assert_eq!(format_args!("{}. 16-bytes piece", "World").estimated_capacity(), 32);
32 }