in starlark/src/values/display.rs [161:214]
fn test_keyed_container() {
struct Wrapped(IndexMap<u32, &'static str>);
impl fmt::Display for Wrapped {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
display_keyed_container(
f,
"prefix[",
"]",
": ",
// just wrap with `"` to make it clearer in the output
self.0.iter().map(|(k, v)| (k, format!("\"{}\"", v))),
)
}
}
assert_eq!("prefix[]", format!("{:}", Wrapped(indexmap! {})));
assert_eq!(
"prefix[1: \"1\"]",
format!("{:}", Wrapped(indexmap! {1 => "1"}))
);
assert_eq!(
"prefix[1: \"1\", 2: \"2\"]",
format!("{:}", Wrapped(indexmap! {1 => "1", 2 => "2"})),
);
assert_eq!(
"prefix[1: \"1\", 2: \"2\", 3: \"3\"]",
format!("{:}", Wrapped(indexmap! {1 => "1", 2 => "2", 3 => "3"})),
);
assert_eq!("prefix[]", format!("{:#}", Wrapped(indexmap! {})));
assert_eq!(
"prefix[ 1: \"1\" ]",
format!("{:#}", Wrapped(indexmap! {1 => "1"}))
);
assert_eq!(
indoc!(
"prefix[
1: \"1\",
2: \"2\"
]"
),
format!("{:#}", Wrapped(indexmap! {1 => "1", 2 => "2"})),
);
assert_eq!(
indoc!(
"prefix[
1: \"1\",
2: \"2\",
3: \"3\"
]"
),
format!("{:#}", Wrapped(indexmap! {1 => "1", 2 => "2", 3 => "3"})),
);
}