Add roundtrip testing and bump format version

This commit is contained in:
Rune Tynan
2021-03-04 18:45:57 -05:00
parent cf5246915b
commit ca48d1566e
4 changed files with 51 additions and 1 deletions

View File

@@ -9,3 +9,6 @@ path = "lib.rs"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
[dev-dependencies]
serde_json = "1.0"

View File

@@ -508,3 +508,47 @@ pub struct Static {
pub mutable: bool,
pub expr: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_struct_info_roundtrip() {
let s = ItemEnum::Struct(Struct {
struct_type: StructType::Plain,
generics: Generics {
params: vec![],
where_predicates: vec![]
},
fields_stripped: false,
fields: vec![],
impls: vec![],
});
let struct_json = serde_json::to_string(&s).unwrap();
let de_s = serde_json::from_str(&struct_json).unwrap();
assert_eq!(s, de_s);
}
#[test]
fn test_union_info_roundtrip() {
let u = ItemEnum::Union(Union {
generics: Generics {
params: vec![],
where_predicates: vec![]
},
fields_stripped: false,
fields: vec![],
impls: vec![],
});
let union_json = serde_json::to_string(&u).unwrap();
let de_u = serde_json::from_str(&union_json).unwrap();
assert_eq!(u, de_u);
}
}