More testing

This commit is contained in:
Michael Pfaff 2022-05-19 13:03:53 -04:00
parent c0cfc8eb82
commit d1d424dc73
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
2 changed files with 20 additions and 2 deletions

View File

@ -9,3 +9,7 @@ serde = [ "dep:serde" ]
[dependencies]
serde = { version = "1", optional = true, features = [ "derive" ] }
[dev-dependencies]
ql = { path = ".", features = [ "serde" ] }
serde_json = { version = "1" }

View File

@ -20,14 +20,28 @@ mod tests {
// just tests that the macro compiles
crate::query_def! {
Foo(FooDef) {
bar: 'dyn (Bar),
#[serde(flatten)]
bar: (Bar),
baz: (bool),
bars: 'vec (Bar),
bars_by_bazs: 'map (bool, Bar),
}
Bar(BarDef) {
baz: (bool),
baz_inner: (bool),
}
}
// make sure A. serde is working and B. we get expected structure
#[test]
fn test_json() {
assert_eq!(serde_json::to_string(&Foo {
bar: Some(Bar {
baz_inner: Some(true),
}),
baz: Some(false),
bars: Some(vec![]),
bars_by_bazs: Some(std::collections::HashMap::new()),
}).ok(), Some(r#"{"baz_inner":true,"baz":false,"bars":[],"bars_by_bazs":{}}"#.to_owned()));
}
}