Skip to content

Commit ca48d15

Browse files
committed
Add roundtrip testing and bump format version
1 parent cf52469 commit ca48d15

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is automatically @generated by Cargo.
22
# It is not intended for manual editing.
3+
version = 3
4+
35
[[package]]
46
name = "addr2line"
57
version = "0.14.0"
@@ -4568,6 +4570,7 @@ name = "rustdoc-json-types"
45684570
version = "0.1.0"
45694571
dependencies = [
45704572
"serde",
4573+
"serde_json",
45714574
]
45724575

45734576
[[package]]

src/librustdoc/json/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
242242
)
243243
})
244244
.collect(),
245-
format_version: 4,
245+
format_version: 5,
246246
};
247247
let mut p = self.out_path.clone();
248248
p.push(output.index.get(&output.root).unwrap().name.clone().unwrap());

src/rustdoc-json-types/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ path = "lib.rs"
99

1010
[dependencies]
1111
serde = { version = "1.0", features = ["derive"] }
12+
13+
[dev-dependencies]
14+
serde_json = "1.0"

src/rustdoc-json-types/lib.rs

+44
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,47 @@ pub struct Static {
508508
pub mutable: bool,
509509
pub expr: String,
510510
}
511+
512+
#[cfg(test)]
513+
mod tests {
514+
use super::*;
515+
516+
#[test]
517+
fn test_struct_info_roundtrip() {
518+
let s = ItemEnum::Struct(Struct {
519+
struct_type: StructType::Plain,
520+
generics: Generics {
521+
params: vec![],
522+
where_predicates: vec![]
523+
},
524+
fields_stripped: false,
525+
fields: vec![],
526+
impls: vec![],
527+
});
528+
529+
let struct_json = serde_json::to_string(&s).unwrap();
530+
531+
let de_s = serde_json::from_str(&struct_json).unwrap();
532+
533+
assert_eq!(s, de_s);
534+
}
535+
536+
#[test]
537+
fn test_union_info_roundtrip() {
538+
let u = ItemEnum::Union(Union {
539+
generics: Generics {
540+
params: vec![],
541+
where_predicates: vec![]
542+
},
543+
fields_stripped: false,
544+
fields: vec![],
545+
impls: vec![],
546+
});
547+
548+
let union_json = serde_json::to_string(&u).unwrap();
549+
550+
let de_u = serde_json::from_str(&union_json).unwrap();
551+
552+
assert_eq!(u, de_u);
553+
}
554+
}

0 commit comments

Comments
 (0)