MCPcopy Create free account
hub / github.com/apache/fory / test_compatible_from_empty_struct

Function test_compatible_from_empty_struct

rust/tests/tests/test_simple_struct.rs:149–169  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

147// Test 5: Compatible mode - empty struct to struct with fields (fields get defaults)
148#[test]
149fn test_compatible_from_empty_struct() {
150 #[derive(ForyStruct, Debug)]
151 struct EmptyData {}
152
153 #[derive(ForyStruct, Debug)]
154 struct DataWithField {
155 value: i32,
156 name: String,
157 }
158
159 let mut fory1 = Fory::builder().xlang(false).compatible(true).build();
160 let mut fory2 = Fory::builder().xlang(false).compatible(true).build();
161 fory1.register::<EmptyData>(102).unwrap();
162 fory2.register::<DataWithField>(102).unwrap();
163
164 let data1 = EmptyData {};
165 let bytes = fory1.serialize(&data1).unwrap();
166 let result: DataWithField = fory2.deserialize(&bytes).unwrap();
167 assert_eq!(result.value, 0); // Default for i32
168 assert_eq!(result.name, String::default()); // Default for String
169}
170
171#[test]
172fn test_compatible_vec_to_empty_struct() {

Callers

nothing calls this directly

Calls 6

serializeMethod · 0.65
deserializeMethod · 0.65
buildMethod · 0.45
compatibleMethod · 0.45
xlangMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected