mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-10 17:07:36 +00:00
Added some basic tests for Option::unzip()
and Option::zip()
(I noticed that zip had no tests)
This commit is contained in:
parent
bc4ce79764
commit
eea3520a8f
@ -399,7 +399,7 @@ fn test_unwrap_drop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn option_ext() {
|
fn option_ext() {
|
||||||
let thing = "{{ f }}";
|
let thing = "{{ f }}";
|
||||||
let f = thing.find("{{");
|
let f = thing.find("{{");
|
||||||
|
|
||||||
@ -407,3 +407,35 @@ pub fn option_ext() {
|
|||||||
println!("None!");
|
println!("None!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zip_options() {
|
||||||
|
let x = Some(10);
|
||||||
|
let y = Some("foo");
|
||||||
|
let z: Option<usize> = None;
|
||||||
|
|
||||||
|
assert_eq!(x.zip(y), Some((10, "foo")));
|
||||||
|
assert_eq!(x.zip(z), None);
|
||||||
|
assert_eq!(z.zip(x), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unzip_options() {
|
||||||
|
let x = Some((10, "foo"));
|
||||||
|
let y = None::<(bool, i32)>;
|
||||||
|
|
||||||
|
assert_eq!(x.unzip(), (Some(10), Some("foo")));
|
||||||
|
assert_eq!(y.unzip(), (None, None));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zip_unzip_roundtrip() {
|
||||||
|
let x = Some(10);
|
||||||
|
let y = Some("foo");
|
||||||
|
|
||||||
|
let z = x.zip(y);
|
||||||
|
assert_eq!(z, Some((10, "foo")));
|
||||||
|
|
||||||
|
let a = z.unzip();
|
||||||
|
assert_eq!(a, (x, y));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user