Skip to content

Commit eea3520

Browse files
committedAug 9, 2021
Added some basic tests for Option::unzip() and Option::zip() (I noticed that zip had no tests)
1 parent bc4ce79 commit eea3520

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed
 

‎library/core/tests/option.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,43 @@ fn test_unwrap_drop() {
399399
}
400400

401401
#[test]
402-
pub fn option_ext() {
402+
fn option_ext() {
403403
let thing = "{{ f }}";
404404
let f = thing.find("{{");
405405

406406
if f.is_none() {
407407
println!("None!");
408408
}
409409
}
410+
411+
#[test]
412+
fn zip_options() {
413+
let x = Some(10);
414+
let y = Some("foo");
415+
let z: Option<usize> = None;
416+
417+
assert_eq!(x.zip(y), Some((10, "foo")));
418+
assert_eq!(x.zip(z), None);
419+
assert_eq!(z.zip(x), None);
420+
}
421+
422+
#[test]
423+
fn unzip_options() {
424+
let x = Some((10, "foo"));
425+
let y = None::<(bool, i32)>;
426+
427+
assert_eq!(x.unzip(), (Some(10), Some("foo")));
428+
assert_eq!(y.unzip(), (None, None));
429+
}
430+
431+
#[test]
432+
fn zip_unzip_roundtrip() {
433+
let x = Some(10);
434+
let y = Some("foo");
435+
436+
let z = x.zip(y);
437+
assert_eq!(z, Some((10, "foo")));
438+
439+
let a = z.unzip();
440+
assert_eq!(a, (x, y));
441+
}

0 commit comments

Comments
 (0)
Please sign in to comment.