46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
use domain::value_objects::{MetadataValue, StructuredData};
|
|
|
|
#[test]
|
|
fn insert_and_get() {
|
|
let mut sd = StructuredData::new();
|
|
sd.insert("key", MetadataValue::String("value".into()));
|
|
assert_eq!(sd.get_string("key"), Some("value"));
|
|
assert_eq!(sd.len(), 1);
|
|
assert!(!sd.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn merge_from_overwrites() {
|
|
let mut a = StructuredData::new();
|
|
a.insert("k", MetadataValue::Integer(1));
|
|
|
|
let mut b = StructuredData::new();
|
|
b.insert("k", MetadataValue::Integer(2));
|
|
|
|
a.merge_from(b);
|
|
assert!(matches!(a.get("k"), Some(MetadataValue::Integer(2))));
|
|
}
|
|
|
|
#[test]
|
|
fn serde_roundtrip() {
|
|
let mut sd = StructuredData::new();
|
|
sd.insert("s", MetadataValue::String("hello".into()));
|
|
sd.insert("i", MetadataValue::Integer(42));
|
|
sd.insert("f", MetadataValue::Float(3.14));
|
|
sd.insert("b", MetadataValue::Boolean(true));
|
|
sd.insert("n", MetadataValue::Null);
|
|
|
|
let json = serde_json::to_string(&sd).unwrap();
|
|
let back: StructuredData = serde_json::from_str(&json).unwrap();
|
|
assert_eq!(sd, back);
|
|
}
|
|
|
|
#[test]
|
|
fn remove_works() {
|
|
let mut sd = StructuredData::new();
|
|
sd.insert("k", MetadataValue::Integer(1));
|
|
let removed = sd.remove("k");
|
|
assert!(matches!(removed, Some(MetadataValue::Integer(1))));
|
|
assert!(sd.is_empty());
|
|
}
|