summaryrefslogtreecommitdiffstats
path: root/third_party/rust/hashlink/tests/serde.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/hashlink/tests/serde.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/hashlink/tests/serde.rs')
-rw-r--r--third_party/rust/hashlink/tests/serde.rs108
1 files changed, 108 insertions, 0 deletions
diff --git a/third_party/rust/hashlink/tests/serde.rs b/third_party/rust/hashlink/tests/serde.rs
new file mode 100644
index 0000000000..d397a245fa
--- /dev/null
+++ b/third_party/rust/hashlink/tests/serde.rs
@@ -0,0 +1,108 @@
+#![cfg(feature = "serde_impl")]
+
+use fxhash::FxBuildHasher;
+use hashlink::{LinkedHashMap, LinkedHashSet};
+use serde_test::{assert_tokens, Token};
+
+#[test]
+fn map_serde_tokens_empty() {
+ let map = LinkedHashMap::<char, u32>::new();
+
+ assert_tokens(&map, &[Token::Map { len: Some(0) }, Token::MapEnd]);
+}
+
+#[test]
+fn map_serde_tokens() {
+ let mut map = LinkedHashMap::new();
+ map.insert('a', 10);
+ map.insert('b', 20);
+ map.insert('c', 30);
+
+ assert_tokens(
+ &map,
+ &[
+ Token::Map { len: Some(3) },
+ Token::Char('a'),
+ Token::I32(10),
+ Token::Char('b'),
+ Token::I32(20),
+ Token::Char('c'),
+ Token::I32(30),
+ Token::MapEnd,
+ ],
+ );
+}
+
+#[test]
+fn map_serde_tokens_empty_generic() {
+ let map = LinkedHashMap::<char, u32, FxBuildHasher>::with_hasher(FxBuildHasher::default());
+
+ assert_tokens(&map, &[Token::Map { len: Some(0) }, Token::MapEnd]);
+}
+
+#[test]
+fn map_serde_tokens_generic() {
+ let mut map = LinkedHashMap::with_hasher(FxBuildHasher::default());
+ map.insert('a', 10);
+ map.insert('b', 20);
+ map.insert('c', 30);
+
+ assert_tokens(
+ &map,
+ &[
+ Token::Map { len: Some(3) },
+ Token::Char('a'),
+ Token::I32(10),
+ Token::Char('b'),
+ Token::I32(20),
+ Token::Char('c'),
+ Token::I32(30),
+ Token::MapEnd,
+ ],
+ );
+}
+
+#[test]
+fn set_serde_tokens_empty() {
+ let set = LinkedHashSet::<u32>::new();
+
+ assert_tokens(&set, &[Token::Seq { len: Some(0) }, Token::SeqEnd]);
+}
+
+#[test]
+fn set_serde_tokens() {
+ let mut set = LinkedHashSet::new();
+ set.insert(10);
+ set.insert(20);
+ set.insert(30);
+
+ assert_tokens(
+ &set,
+ &[
+ Token::Seq { len: Some(3) },
+ Token::I32(10),
+ Token::I32(20),
+ Token::I32(30),
+ Token::SeqEnd,
+ ],
+ );
+}
+
+#[test]
+fn set_serde_tokens_generic() {
+ let mut set = LinkedHashSet::with_hasher(FxBuildHasher::default());
+ set.insert('a');
+ set.insert('b');
+ set.insert('c');
+
+ assert_tokens(
+ &set,
+ &[
+ Token::Seq { len: Some(3) },
+ Token::Char('a'),
+ Token::Char('b'),
+ Token::Char('c'),
+ Token::SeqEnd,
+ ],
+ );
+}