Add to_dynamic test for Option.
@@ -751,7 +751,7 @@ fn test_serde_json() -> serde_json::Result<()> {
#[test]
#[cfg(not(feature = "no_object"))]
fn test_serde_optional() -> Result<(), Box<EvalAltResult>> {
- #[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
struct TestStruct {
foo: Option<char>,
}
@@ -774,6 +774,24 @@ fn test_serde_optional() -> Result<(), Box<EvalAltResult>> {
assert_eq!(from_dynamic::<TestStruct>(&r)?, TestStruct { foo: None });
+ let ts = TestStruct { foo: Some('a') };
+
+ let r = to_dynamic(&ts)?;
+
+ let map = r.cast::<Map>();
+
+ assert_eq!(map.len(), 1);
+ assert_eq!(map.get("foo").unwrap().as_char().unwrap(), 'a');
+
+ let ts = TestStruct { foo: None };
+
+ let r = to_dynamic(&ts)?;
+
+ let map = r.cast::<Map>();
+
+ assert_eq!(map.len(), 1);
+ assert_eq!(map.get("foo").unwrap().as_unit().unwrap(), ());
+
Ok(())
}
