Skip to content

Commit c5f6ecf

Browse files
committed
Add test for Formatter flags.
1 parent 0a07d53 commit c5f6ecf

File tree

1 file changed

+20
-0
lines changed
  • library/coretests/tests/fmt

1 file changed

+20
-0
lines changed

library/coretests/tests/fmt/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ fn formatting_options_ctor() {
5858
}
5959

6060
#[test]
61+
#[allow(deprecated)]
6162
fn formatting_options_flags() {
6263
use core::fmt::*;
6364
for sign in [None, Some(Sign::Plus), Some(Sign::Minus)] {
@@ -75,6 +76,25 @@ fn formatting_options_flags() {
7576
assert_eq!(formatting_options.get_alternate(), alternate);
7677
assert_eq!(formatting_options.get_sign_aware_zero_pad(), sign_aware_zero_pad);
7778
assert_eq!(formatting_options.get_debug_as_hex(), debug_as_hex);
79+
80+
let mut output = String::new();
81+
let fmt = Formatter::new(&mut output, formatting_options);
82+
assert_eq!(fmt.options(), formatting_options);
83+
84+
assert_eq!(fmt.sign_minus(), sign == Some(Sign::Minus));
85+
assert_eq!(fmt.sign_plus(), sign == Some(Sign::Plus));
86+
assert_eq!(fmt.alternate(), alternate);
87+
assert_eq!(fmt.sign_aware_zero_pad(), sign_aware_zero_pad);
88+
89+
// The flags method is deprecated.
90+
// This checks compatibility with older versions of Rust.
91+
assert_eq!(fmt.flags() & 1 != 0, sign == Some(Sign::Plus));
92+
assert_eq!(fmt.flags() & 2 != 0, sign == Some(Sign::Minus));
93+
assert_eq!(fmt.flags() & 4 != 0, alternate);
94+
assert_eq!(fmt.flags() & 8 != 0, sign_aware_zero_pad);
95+
assert_eq!(fmt.flags() & 16 != 0, debug_as_hex == Some(DebugAsHex::Lower));
96+
assert_eq!(fmt.flags() & 32 != 0, debug_as_hex == Some(DebugAsHex::Upper));
97+
assert_eq!(fmt.flags() & 0xFFFF_FFC0, 0);
7898
}
7999
}
80100
}

0 commit comments

Comments
 (0)