mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
test
This commit is contained in:
parent
c9bcc69266
commit
3742175824
1 changed files with 39 additions and 0 deletions
|
@ -14,6 +14,7 @@ mod tests {
|
|||
type_registry::TypeRegistry,
|
||||
DynamicStruct, FromReflect, Reflect,
|
||||
};
|
||||
use bevy_reflect_derive::TypePath;
|
||||
use serde::de::DeserializeSeed;
|
||||
|
||||
#[test]
|
||||
|
@ -179,6 +180,44 @@ mod tests {
|
|||
let expected = value.clone_value();
|
||||
let result = reflect_deserializer.deserialize(&mut deserializer).unwrap();
|
||||
|
||||
assert!(expected
|
||||
.reflect_partial_eq(result.as_partial_reflect())
|
||||
.unwrap());
|
||||
}
|
||||
#[test]
|
||||
fn should_roundtrip_phantom_data() {
|
||||
use core::marker::PhantomData;
|
||||
|
||||
#[derive(Reflect)]
|
||||
struct TestStruct<'a, T> {
|
||||
a: i32,
|
||||
_marker: PhantomData<&'a T>,
|
||||
}
|
||||
|
||||
#[derive(TypePath)]
|
||||
struct MarkerType;
|
||||
|
||||
let mut registry = TypeRegistry::default();
|
||||
registry.register::<TestStruct<MarkerType>>();
|
||||
|
||||
let value: DynamicStruct = TestStruct::<'static, MarkerType> {
|
||||
a: 123,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
.clone_dynamic();
|
||||
|
||||
let serializer = ReflectSerializer::new(&value, ®istry);
|
||||
|
||||
let expected = r#"{"bevy_reflect::serde::tests::TestStruct":(a:123)}"#;
|
||||
let result = ron::ser::to_string(&serializer).unwrap();
|
||||
assert_eq!(expected, result);
|
||||
|
||||
let mut deserializer = ron::de::Deserializer::from_str(&result).unwrap();
|
||||
let reflect_deserializer = ReflectDeserializer::new(®istry);
|
||||
|
||||
let expected = value.clone_value();
|
||||
let result = reflect_deserializer.deserialize(&mut deserializer).unwrap();
|
||||
|
||||
assert!(expected
|
||||
.reflect_partial_eq(result.as_partial_reflect())
|
||||
.unwrap());
|
||||
|
|
Loading…
Reference in a new issue