File tree 1 file changed +33
-1
lines changed
1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -399,11 +399,43 @@ fn test_unwrap_drop() {
399
399
}
400
400
401
401
#[ test]
402
- pub fn option_ext ( ) {
402
+ fn option_ext ( ) {
403
403
let thing = "{{ f }}" ;
404
404
let f = thing. find ( "{{" ) ;
405
405
406
406
if f. is_none ( ) {
407
407
println ! ( "None!" ) ;
408
408
}
409
409
}
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
+ }
You can’t perform that action at this time.
0 commit comments