You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let bson = b"\x2d\x00\x00\x00\x01\x69\x6e\x66\x00\x00\x00\x00\x00\x00\x00\xf0\x7f\x01\x6e\x69\x6e\x66\x00\x00\x00\x00\x00\x00\x00\xf0\xff\x01\x6e\x61\x6e\x00\x00\x00\x00\x00\x00\x00\xf8\x7f\x00";
151
+
152
+
#[derive(Deserialize)]
153
+
structTestDoc{
154
+
inf:f64,
155
+
ninf:f64,
156
+
nan:f64,
157
+
}
158
+
159
+
let doc:TestDoc = from_bytes(bson).expect("should deserialize");
160
+
assert_eq!(doc.inf,f64::INFINITY);
161
+
assert_eq!(doc.ninf,f64::NEG_INFINITY);
162
+
assert!(doc.nan.is_nan());
163
+
}
164
+
165
+
#[test]
166
+
fntest_empty_string(){
167
+
// {"empty": ""}
168
+
let bson = b"\x11\x00\x00\x00\x02empty\x00\x01\x00\x00\x00\x00\x00";
169
+
170
+
#[derive(Deserialize)]
171
+
structTestDoc<'a>{
172
+
empty:&'astr,
173
+
}
174
+
175
+
let doc:TestDoc = from_bytes(bson).expect("should deserialize");
176
+
assert_eq!(doc.empty,"");
177
+
}
178
+
179
+
#[test]
180
+
fntest_unicode_string(){
181
+
// {"unicode": "🦀💖"}
182
+
let bson = b"\x1b\x00\x00\x00\x02unicode\x00\x09\x00\x00\x00\xf0\x9f\xa6\x80\xf0\x9f\x92\x96\x00\x00";
183
+
184
+
#[derive(Deserialize)]
185
+
structTestDoc<'a>{
186
+
unicode:&'astr,
187
+
}
188
+
189
+
let doc:TestDoc = from_bytes(bson).expect("should deserialize");
190
+
assert_eq!(doc.unicode,"🦀💖");
191
+
}
192
+
193
+
#[test]
194
+
fntest_boolean_values(){
195
+
// {"true_val": true, "false_val": false}
196
+
let bson = b"\x1c\x00\x00\x00\x08true_val\x00\x01\x08false_val\x00\x00\x00";
197
+
198
+
#[derive(Deserialize)]
199
+
structTestDoc{
200
+
true_val:bool,
201
+
false_val:bool,
202
+
}
203
+
204
+
let doc:TestDoc = from_bytes(bson).expect("should deserialize");
205
+
assert_eq!(doc.true_val,true);
206
+
assert_eq!(doc.false_val,false);
207
+
}
208
+
209
+
#[test]
210
+
fntest_null_value(){
211
+
// {"null_val": null}
212
+
let bson = b"\x0f\x00\x00\x00\x0anull_val\x00\x00";
213
+
214
+
#[derive(Deserialize)]
215
+
structTestDoc{
216
+
null_val:Option<i32>,
217
+
}
218
+
219
+
let doc:TestDoc = from_bytes(bson).expect("should deserialize");
220
+
assert_eq!(doc.null_val,None);
221
+
}
222
+
223
+
#[test]
224
+
fntest_empty_document(){
225
+
// {}
226
+
let bson = b"\x05\x00\x00\x00\x00";
227
+
228
+
#[derive(Deserialize)]
229
+
structTestDoc{}
230
+
231
+
let _doc:TestDoc = from_bytes(bson).expect("should deserialize");
0 commit comments