#![forbid(unsafe_code)]
use facet::Facet;
use facet_format::DeserializeError;
use facet_format_suite::{CaseOutcome, CaseSpec, FormatSuite, all_cases, msgpack};
use facet_msgpack::{MsgPackParser, to_vec};
use libtest_mimic::{Arguments, Failed, Trial};
struct MsgPackSlice;
impl FormatSuite for MsgPackSlice {
type Error = DeserializeError;
fn format_name() -> &'static str {
"facet-msgpack/slice"
}
fn highlight_language() -> Option<&'static str> {
None }
fn deserialize<T>(input: &[u8]) -> Result<T, Self::Error>
where
T: Facet<'static> + core::fmt::Debug,
{
use facet_format::FormatDeserializer;
let mut parser = MsgPackParser::new(input);
let mut de = FormatDeserializer::new_owned(&mut parser);
de.deserialize_root::<T>()
}
fn serialize<T>(value: &T) -> Option<Result<Vec<u8>, String>>
where
for<'facet> T: Facet<'facet>,
T: core::fmt::Debug,
{
Some(to_vec(value).map_err(|e| e.to_string()))
}
fn struct_single_field() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::struct_single_field_bytes())
}
fn sequence_numbers() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::sequence_numbers_bytes())
}
fn sequence_mixed_scalars() -> CaseSpec {
CaseSpec::skip("MixedScalar enum serialization differs between serde and facet")
}
fn struct_nested() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::struct_nested_bytes())
}
fn enum_complex() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::enum_complex_bytes())
}
fn attr_rename_field() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_rename_all_camel() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_default_field() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_default_struct() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_default_function() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn option_none() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::option_none_bytes())
}
fn option_some() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::option_some_bytes())
}
fn option_null() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::option_none_bytes())
}
fn attr_skip_serializing() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_skip_serializing_if() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_skip() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn enum_internally_tagged() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn enum_adjacently_tagged() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn struct_flatten() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn transparent_newtype() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn deny_unknown_fields() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn error_type_mismatch_string_to_int() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn error_type_mismatch_object_to_array() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn error_missing_required_field() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_alias() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_rename_vs_alias_precedence() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_rename_all_kebab() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_rename_all_screaming() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_rename_unicode() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn attr_rename_special_chars() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn proxy_container() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn proxy_field_level() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn proxy_validation_error() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn proxy_with_option() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn proxy_with_enum() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn proxy_with_transparent() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn opaque_proxy() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn opaque_proxy_option() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn transparent_multilevel() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn transparent_option() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn transparent_nonzero() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn flatten_optional_some() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn flatten_optional_none() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn flatten_overlapping_fields_error() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn flatten_multilevel() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn flatten_multiple_enums() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn scalar_bool() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::scalar_bool_bytes())
}
fn scalar_integers() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::scalar_integers_bytes())
}
fn scalar_floats() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::scalar_floats_bytes())
}
fn map_string_keys() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::map_string_keys_bytes())
}
fn tuple_simple() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::tuple_simple_bytes())
}
fn tuple_nested() -> CaseSpec {
CaseSpec::skip("Nested tuple representation differs between serde and facet")
}
fn tuple_empty() -> CaseSpec {
CaseSpec::skip("Empty tuple representation differs: serde=null, facet=[]")
}
fn tuple_single_element() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::tuple_single_element_bytes())
}
fn tuple_struct_variant() -> CaseSpec {
CaseSpec::skip("Enum tuple variants have different representation in serde vs facet")
}
fn tuple_newtype_variant() -> CaseSpec {
CaseSpec::skip("Enum newtype variants have different representation in serde vs facet")
}
fn enum_unit_variant() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::enum_unit_variant_bytes())
}
fn numeric_enum() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn signed_numeric_enum() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn inferred_numeric_enum() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn enum_untagged() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn enum_variant_rename() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn untagged_with_null() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn untagged_newtype_variant() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn untagged_as_field() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn untagged_unit_only() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn box_wrapper() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::box_wrapper_bytes())
}
fn arc_wrapper() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::arc_wrapper_bytes())
}
fn rc_wrapper() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::rc_wrapper_bytes())
}
fn set_btree() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::set_btree_bytes())
}
fn scalar_integers_16() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::scalar_integers_16_bytes())
}
fn scalar_integers_128() -> CaseSpec {
CaseSpec::skip("i128/u128 serialized as byte arrays by serde, not native integers")
}
fn scalar_integers_size() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::scalar_integers_size_bytes())
}
fn nonzero_integers() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::nonzero_integers_bytes())
}
fn cow_str() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::cow_str_bytes())
}
fn bytes_vec_u8() -> CaseSpec {
CaseSpec::skip("Vec<u8> representation differs: serde=binary, facet=array")
}
fn array_fixed_size() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::array_fixed_size_bytes())
}
fn skip_unknown_fields() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::skip_unknown_fields_bytes())
}
fn string_escapes() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, no string escape sequences")
}
fn unit_struct() -> CaseSpec {
CaseSpec::skip("Unit struct representation differs: serde=[], facet={}")
}
fn newtype_u64() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn newtype_string() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn char_scalar() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::char_scalar_bytes())
}
fn hashset() -> CaseSpec {
CaseSpec::skip("HashSet element ordering is non-deterministic")
}
fn vec_nested() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::vec_nested_bytes())
.without_roundtrip("Round-trip comparison has issues with nested vecs")
}
fn uuid() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn ulid() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn camino_path() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn ordered_float() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn rust_decimal() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn scalar_floats_scientific() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, no scientific notation")
}
fn string_escapes_extended() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, no string escape sequences")
}
fn box_str() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn arc_str() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn rc_str() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn arc_slice() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
#[cfg(feature = "yoke")]
fn yoke_cow_str() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
#[cfg(feature = "yoke")]
fn yoke_custom() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn nonzero_integers_extended() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn time_offset_datetime() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn jiff_timestamp() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn jiff_civil_datetime() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn jiff_civil_date() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn jiff_civil_time() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn chrono_datetime_utc() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn chrono_naive_datetime() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn chrono_naive_date() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn chrono_naive_time() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn chrono_in_vec() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn chrono_duration() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn chrono_duration_negative() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn std_duration() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn bytes_bytes() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn bytes_bytes_mut() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn bytestring() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn compact_string() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn smartstring() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn smol_str() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn iddqd_id_hash_map() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn iddqd_id_ord_map() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn iddqd_bi_hash_map() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn iddqd_tri_hash_map() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, requires binary input not JSON strings")
}
fn value_null() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, DynamicValue not supported")
}
fn value_bool() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, DynamicValue not supported")
}
fn value_integer() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, DynamicValue not supported")
}
fn value_float() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, DynamicValue not supported")
}
fn value_string() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, DynamicValue not supported")
}
fn value_array() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, DynamicValue not supported")
}
fn value_object() -> CaseSpec {
CaseSpec::skip("MsgPack is a binary format, DynamicValue not supported")
}
fn net_ip_addr_v4() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::net_ip_addr_v4_bytes())
}
fn net_ip_addr_v6() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::net_ip_addr_v6_bytes())
}
fn net_ipv4_addr() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::net_ipv4_addr_bytes())
}
fn net_ipv6_addr() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::net_ipv6_addr_bytes())
}
fn net_socket_addr_v4() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::net_socket_addr_v4_bytes())
}
fn net_socket_addr_v6() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::net_socket_addr_v6_bytes())
}
fn net_socket_addr_v4_explicit() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::net_socket_addr_v4_explicit_bytes())
}
fn net_socket_addr_v6_explicit() -> CaseSpec {
CaseSpec::from_bytes_vec(msgpack::net_socket_addr_v6_explicit_bytes())
}
}
fn main() {
use std::sync::Arc;
let args = Arguments::from_args();
let cases: Vec<Arc<_>> = all_cases::<MsgPackSlice>()
.into_iter()
.map(Arc::new)
.collect();
let mut trials: Vec<Trial> = Vec::new();
for case in &cases {
let name = format!("{}::{}", MsgPackSlice::format_name(), case.id);
let skip_reason = case.skip_reason();
let case = Arc::clone(case);
let mut trial = Trial::test(name, move || match case.run() {
CaseOutcome::Passed => Ok(()),
CaseOutcome::Skipped(_) => Ok(()),
CaseOutcome::Failed(msg) => Err(Failed::from(msg)),
});
if skip_reason.is_some() {
trial = trial.with_ignored_flag(true);
}
trials.push(trial);
}
libtest_mimic::run(&args, trials).exit()
}