diff options
| author | bors <bors@rust-lang.org> | 2017-12-20 06:38:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-20 06:38:15 +0000 |
| commit | 6dbf0ba691f756ebb89ffe0fd082f3d057027273 (patch) | |
| tree | 57a6519a97af4d3135a1a55bee412dceded08d46 /src/libcore/tests | |
| parent | 588f7db8ef588ea7e349817bb44b4e37bfd92745 (diff) | |
| parent | bf087895102f1ab275a7ceed9f789dcfb7e172f3 (diff) | |
| download | rust-6dbf0ba691f756ebb89ffe0fd082f3d057027273.tar.gz rust-6dbf0ba691f756ebb89ffe0fd082f3d057027273.zip | |
Auto merge of #46233 - SimonSapin:fmt-debuglist-flags, r=sfackler
Make fmt::DebugList and friends forward formatting parameters
For example, formatting slice of integers with `{:04?}` should zero-pad each integer.
This also affects every use of `#[derive(Debug)]`.
Diffstat (limited to 'src/libcore/tests')
| -rw-r--r-- | src/libcore/tests/fmt/builders.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/libcore/tests/fmt/builders.rs b/src/libcore/tests/fmt/builders.rs index e71e61bda5e..b7233658e93 100644 --- a/src/libcore/tests/fmt/builders.rs +++ b/src/libcore/tests/fmt/builders.rs @@ -496,3 +496,58 @@ mod debug_list { format!("{:#?}", Bar)); } } + +#[test] +fn test_formatting_parameters_are_forwarded() { + use std::collections::{BTreeMap, BTreeSet}; + #[derive(Debug)] + struct Foo { + bar: u32, + baz: u32, + } + let struct_ = Foo { bar: 1024, baz: 7 }; + let tuple = (1024, 7); + let list = [1024, 7]; + let mut map = BTreeMap::new(); + map.insert("bar", 1024); + map.insert("baz", 7); + let mut set = BTreeSet::new(); + set.insert(1024); + set.insert(7); + + assert_eq!(format!("{:03?}", struct_), "Foo { bar: 1024, baz: 007 }"); + assert_eq!(format!("{:03?}", tuple), "(1024, 007)"); + assert_eq!(format!("{:03?}", list), "[1024, 007]"); + assert_eq!(format!("{:03?}", map), r#"{"bar": 1024, "baz": 007}"#); + assert_eq!(format!("{:03?}", set), "{007, 1024}"); + assert_eq!(format!("{:#03?}", struct_), " +Foo { + bar: 1024, + baz: 007 +} + ".trim()); + assert_eq!(format!("{:#03?}", tuple), " +( + 1024, + 007 +) + ".trim()); + assert_eq!(format!("{:#03?}", list), " +[ + 1024, + 007 +] + ".trim()); + assert_eq!(format!("{:#03?}", map), r#" +{ + "bar": 1024, + "baz": 007 +} + "#.trim()); + assert_eq!(format!("{:#03?}", set), " +{ + 007, + 1024 +} + ".trim()); +} |
