Skip to content

Commit 06253c2

Browse files
committed
test for struct with None value
1 parent 99f8582 commit 06253c2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/test.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,17 @@ fn readme_bencode_example() {
349349
let list_serialize: Vec<u8> = ser.into();
350350
assert_eq!(String::from_utf8(list_serialize).unwrap(), "l3:one3:two5:threei4ee");
351351
}
352+
353+
#[test]
354+
fn struct_none_vals() {
355+
#[derive(Serialize)]
356+
struct Fake {
357+
a: Option<i32>,
358+
b: Option<i32>
359+
};
360+
let f = Fake { a: None, b: Some(1) };
361+
let mut ser = Encoder::new();
362+
f.serialize(&mut ser).unwrap();
363+
let r: Vec<u8> = ser.into();
364+
assert_eq!(String::from_utf8(r).unwrap(), "d1:bi1ee");
365+
}

0 commit comments

Comments
 (0)