aboutsummaryrefslogtreecommitdiff
path: root/common/object/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'common/object/src/tests.rs')
-rw-r--r--common/object/src/tests.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/common/object/src/tests.rs b/common/object/src/tests.rs
new file mode 100644
index 0000000..35a29ba
--- /dev/null
+++ b/common/object/src/tests.rs
@@ -0,0 +1,39 @@
+/*
+ This file is part of jellything (https://codeberg.org/metamuffin/jellything)
+ which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
+ Copyright (C) 2026 metamuffin <metamuffin.org>
+*/
+use crate::{ObjectBuffer, Tag, TypedTag};
+use std::marker::PhantomData;
+
+const NAME: TypedTag<&str> = TypedTag(Tag(15), PhantomData);
+const AGE: TypedTag<u32> = TypedTag(Tag(13), PhantomData);
+const FRIEND: TypedTag<&str> = TypedTag(Tag(54321), PhantomData);
+
+fn test_object() -> ObjectBuffer {
+ ObjectBuffer::new(&mut [
+ (NAME.0, &"Bob"),
+ (AGE.0, &35_u32),
+ (FRIEND.0, &"Alice"),
+ (FRIEND.0, &"Charlie"),
+ ])
+}
+
+#[test]
+fn read_single_field() {
+ let bob = test_object();
+ let bob = bob.as_object();
+ assert_eq!(bob.get(NAME), Some("Bob"));
+ assert_eq!(bob.get(AGE), Some(35));
+}
+
+#[test]
+fn read_multi_field() {
+ let bob = test_object();
+ let bob = bob.as_object();
+
+ let mut friends = bob.iter(FRIEND);
+ assert_eq!(friends.next(), Some("Alice"));
+ assert_eq!(friends.next(), Some("Charlie"));
+ assert_eq!(friends.next(), None);
+}