Skip to content

Commit

Permalink
msgpack: extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
uint committed May 10, 2024
1 parent 714b6df commit f43de0d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/std/src/msgpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,38 @@ mod tests {
}
);
}

#[test]
fn deserialize_new_fields_in_the_middle() {
// fields can be added, but only to the end of the struct

#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct TestV1 {
a: String,
b: u32,
}

#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct TestV2 {
a: String,
#[serde(default)]
c: u8,
b: u32,
}

let v1 = TestV1 {
a: "foo".to_string(),
b: 999999,
};
let v2: TestV2 = from_msgpack(to_msgpack_vec(&v1).unwrap()).unwrap();

assert_eq!(
v2,
TestV2 {
a: "foo".to_string(),
c: 0,
b: 999999,
}
);
}
}

0 comments on commit f43de0d

Please sign in to comment.