Skip to content

Commit fb5f83f

Browse files
committed
msgpack: extra test
1 parent 7303c0c commit fb5f83f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

packages/std/src/msgpack.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,38 @@ mod tests {
187187
}
188188
);
189189
}
190+
191+
#[test]
192+
fn deserialize_new_fields_in_the_middle() {
193+
// fields can be added, but only to the end of the struct
194+
195+
#[derive(Serialize, Deserialize, Debug, PartialEq)]
196+
struct TestV1 {
197+
a: String,
198+
b: u32,
199+
}
200+
201+
#[derive(Serialize, Deserialize, Debug, PartialEq)]
202+
struct TestV2 {
203+
a: String,
204+
#[serde(default)]
205+
c: u8,
206+
b: u32,
207+
}
208+
209+
let v1 = TestV1 {
210+
a: "foo".to_string(),
211+
b: 999999,
212+
};
213+
let v2: TestV2 = from_msgpack(to_msgpack_vec(&v1).unwrap()).unwrap();
214+
215+
assert_eq!(
216+
v2,
217+
TestV2 {
218+
a: "foo".to_string(),
219+
c: 0,
220+
b: 999999,
221+
}
222+
);
223+
}
190224
}

0 commit comments

Comments
 (0)