File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -123,4 +123,68 @@ mod tests {
123
123
let deserialized: SomeMsg = from_msgpack ( serialized) . unwrap ( ) ;
124
124
assert_eq ! ( deserialized, msg) ;
125
125
}
126
+
127
+ #[ test]
128
+ #[ should_panic( expected = "invalid type: string \\ \" foo\\ \" , expected u32" ) ]
129
+ fn deserialize_different_field_order_unsupported ( ) {
130
+ #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
131
+ struct TestV1 {
132
+ a : String ,
133
+ b : u32 ,
134
+ c : u64 ,
135
+ }
136
+
137
+ #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
138
+ struct TestV2 {
139
+ b : u32 ,
140
+ c : u64 ,
141
+ a : String ,
142
+ }
143
+
144
+ let v1 = TestV1 {
145
+ a : "foo" . to_string ( ) ,
146
+ b : 42 ,
147
+ c : 18446744073709551615 ,
148
+ } ;
149
+
150
+ let v2: TestV2 = from_msgpack ( to_msgpack_vec ( & v1) . unwrap ( ) ) . unwrap ( ) ;
151
+ assert_eq ! (
152
+ v2,
153
+ TestV2 {
154
+ b: 42 ,
155
+ c: 18446744073709551615 ,
156
+ a: "foo" . to_string( )
157
+ }
158
+ ) ;
159
+ }
160
+
161
+ #[ test]
162
+ fn deserialize_new_fields ( ) {
163
+ // fields can be added, but only to the end of the struct
164
+
165
+ #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
166
+ struct TestV1 {
167
+ a : String ,
168
+ }
169
+
170
+ #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
171
+ struct TestV2 {
172
+ a : String ,
173
+ #[ serde( default ) ]
174
+ b : u32 ,
175
+ }
176
+
177
+ let v1 = TestV1 {
178
+ a : "foo" . to_string ( ) ,
179
+ } ;
180
+ let v2: TestV2 = from_msgpack ( to_msgpack_vec ( & v1) . unwrap ( ) ) . unwrap ( ) ;
181
+
182
+ assert_eq ! (
183
+ v2,
184
+ TestV2 {
185
+ a: "foo" . to_string( ) ,
186
+ b: 0
187
+ }
188
+ ) ;
189
+ }
126
190
}
You can’t perform that action at this time.
0 commit comments