forked from yegor256/micromap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.rs
39 lines (33 loc) · 944 Bytes
/
debug.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-FileCopyrightText: Copyright (c) 2023-2025 Yegor Bugayenko
// SPDX-License-Identifier: MIT
use crate::Map;
use core::fmt::{self, Debug, Formatter};
impl<K: PartialEq + Debug, V: Debug, const N: usize> Debug for Map<K, V, N> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_map().entries(self.iter()).finish()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn debugs_map() {
let mut m: Map<String, i32, 10> = Map::new();
m.insert("one".to_string(), 42);
m.insert("two".to_string(), 16);
assert_eq!(r#"{"one": 42, "two": 16}"#, format!("{:?}", m));
}
#[test]
fn debug_alternate_map() {
let mut m: Map<String, i32, 10> = Map::new();
m.insert("one".to_string(), 42);
m.insert("two".to_string(), 16);
assert_eq!(
r#"{
"one": 42,
"two": 16,
}"#,
format!("{:#?}", m)
);
}
}