Add to_dynamic test for Option.
This commit is contained in:
parent
a3a527923a
commit
5dae2b07f7
@ -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(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user