]> git.proxmox.com Git - rustc.git/blame - src/libcore/tests/fmt/mod.rs
New upstream version 1.42.0+dfsg1
[rustc.git] / src / libcore / tests / fmt / mod.rs
CommitLineData
c34b1796 1mod builders;
b039eaaf
SL
2mod float;
3mod num;
1a4d82fc 4
970d7e83 5#[test]
1a4d82fc
JJ
6fn test_format_flags() {
7 // No residual flags left by pointer formatting
8 let p = "".as_ptr();
85aaf69f 9 assert_eq!(format!("{:p} {:x}", p, 16), format!("{:p} 10", p));
62682a34
SL
10
11 assert_eq!(format!("{: >3}", 'a'), " a");
970d7e83 12}
7453a54e
SL
13
14#[test]
15fn test_pointer_formats_data_pointer() {
16 let b: &[u8] = b"";
17 let s: &str = "";
18 assert_eq!(format!("{:p}", s), format!("{:p}", s.as_ptr()));
19 assert_eq!(format!("{:p}", b), format!("{:p}", b.as_ptr()));
20}
8bb4bdeb
XL
21
22#[test]
23fn test_estimated_capacity() {
24 assert_eq!(format_args!("").estimated_capacity(), 0);
25 assert_eq!(format_args!("{}", "").estimated_capacity(), 0);
26 assert_eq!(format_args!("Hello").estimated_capacity(), 5);
27 assert_eq!(format_args!("Hello, {}!", "").estimated_capacity(), 16);
28 assert_eq!(format_args!("{}, hello!", "World").estimated_capacity(), 0);
29 assert_eq!(format_args!("{}. 16-bytes piece", "World").estimated_capacity(), 32);
30}
dfeec247
XL
31
32#[test]
33fn pad_integral_resets() {
34 struct Bar;
35
36 impl core::fmt::Display for Bar {
37 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
38 "1".fmt(f)?;
39 f.pad_integral(true, "", "5")?;
40 "1".fmt(f)
41 }
42 }
43
44 assert_eq!(format!("{:<03}", Bar), "1 0051 ");
45}