]> git.lizzy.rs Git - rust.git/commitdiff
Added some basic tests for `Option::unzip()` and `Option::zip()` (I noticed that...
authorChase Wilson <me@chasewilson.dev>
Fri, 30 Jul 2021 18:13:59 +0000 (13:13 -0500)
committerChase Wilson <me@chasewilson.dev>
Mon, 9 Aug 2021 15:24:00 +0000 (10:24 -0500)
library/core/tests/option.rs

index 88ea15a3b33fac90de5bdb2c8ed7fee6dae1e2c0..cd8fdebe36a05a1620ee90daf9417f1e45575afd 100644 (file)
@@ -399,7 +399,7 @@ fn unwrap<T>(o: Option<T>) -> T {
 }
 
 #[test]
-pub fn option_ext() {
+fn option_ext() {
     let thing = "{{ f }}";
     let f = thing.find("{{");
 
@@ -407,3 +407,35 @@ pub fn option_ext() {
         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));
+}