Add roundtrip testing and bump format version
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "addr2line"
|
name = "addr2line"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
@@ -4568,6 +4570,7 @@ name = "rustdoc-json-types"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
format_version: 4,
|
format_version: 5,
|
||||||
};
|
};
|
||||||
let mut p = self.out_path.clone();
|
let mut p = self.out_path.clone();
|
||||||
p.push(output.index.get(&output.root).unwrap().name.clone().unwrap());
|
p.push(output.index.get(&output.root).unwrap().name.clone().unwrap());
|
||||||
|
|||||||
@@ -9,3 +9,6 @@ path = "lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
serde_json = "1.0"
|
||||||
|
|||||||
@@ -508,3 +508,47 @@ pub struct Static {
|
|||||||
pub mutable: bool,
|
pub mutable: bool,
|
||||||
pub expr: String,
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user