1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
use super::*; mod error; mod ser; mod de; pub use self::error::Error; pub use self::ser::to_tree; pub use self::de::from_tree; #[cfg(test)] mod tests { use super::*; #[derive(Debug, Serialize, Deserialize)] struct Data { str_prop: String, usize_prop: usize, float_prop: f64, } #[test] fn serialization() { let d = Data { str_prop: "String property value".to_string(), usize_prop: 130, float_prop: 12.5, }; let json = r#"{"str_prop":"String property value","usize_prop":130,"float_prop":12.5}"#; let n = self::ser::to_tree(&d).unwrap(); assert_eq!(n.to_json(), json); } #[test] fn deserialization() { let json = r#"{ "str_prop": "String property value", "usize_prop": 130, "float_prop": 12.5 }"#; let n = NodeRef::from_json(json).unwrap(); let d: Data = self::de::from_tree(&n).unwrap(); assert_eq!(d.str_prop, "String property value"); assert_eq!(d.usize_prop, 130); assert_eq!(d.float_prop, 12.5); } }