Add serde tests

This commit is contained in:
hodasemi 2024-03-25 15:10:42 +01:00
parent 5f63f4115e
commit a5045770ca

View file

@ -67,6 +67,35 @@ impl ElementDescriptor {
} }
} }
#[test]
fn serde_roundtrip() {
let descriptor = ElementDescriptor::new(
Color::try_from("#1540e6").unwrap(),
Color::try_from("#0c1d5f").unwrap(),
5,
);
let s = serde_json::to_string(&descriptor).unwrap();
let res = serde_json::from_str(&s).unwrap();
assert_eq!(descriptor, res);
}
#[test]
fn serde_serialization() {
let s = "{\"background_color\":\"#1540e6\",\"border_color\":\"#0c1d5f\",\"border_thickness\":{\"Pixel\":5}}";
let res = serde_json::from_str(&s).unwrap();
let descriptor = ElementDescriptor::new(
Color::try_from("#1540e6").unwrap(),
Color::try_from("#0c1d5f").unwrap(),
5,
);
assert_eq!(descriptor, res);
}
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
struct ElementDefinition { struct ElementDefinition {
width: u32, width: u32,