Add serde tests
This commit is contained in:
parent
5f63f4115e
commit
a5045770ca
1 changed files with 29 additions and 0 deletions
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue