use anyhow::Result;
use fbthrift_conformance::AnyRegistry;
use maplit::btreemap;
use protocol::StandardProtocol;
use testset::struct_map_string_i32;
fn test_for_protocol(protocol: StandardProtocol) -> Result<()> {
let mut registry = AnyRegistry::new();
registry.register_type::<struct_map_string_i32>()?;
let original = struct_map_string_i32 {
field_1: btreemap! {"Answer to the Ultimate Question of Life, the Universe, and Everything.".to_owned() => 42},
..Default::default()
};
let any_obj = registry.store(&original, protocol)?;
assert!(any_obj.typeHashPrefixSha2_256.is_some());
assert_eq!(protocol, any_obj.protocol.unwrap());
let loaded = registry.load(&any_obj)?;
assert_eq!(original, loaded);
Ok(())
}
#[test]
fn test_round_trip() -> Result<()> {
let protocols = vec![
StandardProtocol::Binary,
StandardProtocol::Compact,
StandardProtocol::SimpleJson,
];
for protocol in protocols {
test_for_protocol(protocol)?;
}
Ok(())
}