Debian Codegraph @

third_party/rust/serde_with/tests/serde_as/collections.rs

raw
1 use super::*;
2 use fnv::{FnvHashMap, FnvHashSet};
3
4 /// Test that `HashSet`s are also supported with non-default hashers.
5 #[test]
6 fn test_fnv_hashset() {
7 #[serde_as]
8 #[derive(Debug, Serialize, Deserialize, PartialEq)]
9 struct S(#[serde_as(as = "FnvHashSet<DisplayFromStr>")] FnvHashSet<u32>);
10
11 // Normal
12 is_equal(
13 S([1, 2, 3, 4, 5].iter().copied().collect()),
14 expect![[r#"
15 [
16 "5",
17 "4",
18 "1",
19 "3",
20 "2"
21 ]"#]],
22 );
23 is_equal(S(FnvHashSet::default()), expect![[r#"[]"#]]);
24 }
25
26 /// Test that `HashSet`s are also supported with non-default hashers.
27 #[test]
28 fn test_fnv_hashmap() {
29 #[serde_as]
30 #[derive(Debug, Serialize, Deserialize, PartialEq)]
31 struct S(#[serde_as(as = "FnvHashMap<DisplayFromStr, DisplayFromStr>")] FnvHashMap<u8, u32>);
32
33 // Normal
34 is_equal(
35 S([(1, 1), (3, 3), (111, 111)].iter().copied().collect()),
36 expect![[r#"
37 {
38 "1": "1",
39 "3": "3",
40 "111": "111"
41 }"#]],
42 );
43 is_equal(S(FnvHashMap::default()), expect![[r#"{}"#]]);
44 }