1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use core::nonzero::NonZero;
12 use core::option::Option;
13 use core::option::Option::{Some, None};
14 use std::mem::size_of;
17 fn test_create_nonzero_instance() {
24 fn test_size_nonzero_in_option() {
25 assert_eq!(size_of::<NonZero<u32>>(), size_of::<Option<NonZero<u32>>>());
29 fn test_match_on_nonzero_option() {
34 Some(val) => assert_eq!(*val, 42),
35 None => panic!("unexpected None while matching on Some(NonZero(_))")
38 match unsafe { Some(NonZero::new(43)) } {
39 Some(val) => assert_eq!(*val, 43),
40 None => panic!("unexpected None while matching on Some(NonZero(_))")
45 fn test_match_option_empty_vec() {
46 let a: Option<Vec<isize>> = Some(vec![]);
48 None => panic!("unexpected None while matching on Some(vec![])"),
54 fn test_match_option_vec() {
55 let a = Some(vec![1, 2, 3, 4]);
57 Some(v) => assert_eq!(v, [1, 2, 3, 4]),
58 None => panic!("unexpected None while matching on Some(vec![1, 2, 3, 4])")
63 fn test_match_option_rc() {
66 let five = Rc::new(5);
68 Some(r) => assert_eq!(*r, 5),
69 None => panic!("unexpected None while matching on Some(Rc::new(5))")
74 fn test_match_option_arc() {
77 let five = Arc::new(5);
79 Some(a) => assert_eq!(*a, 5),
80 None => panic!("unexpected None while matching on Some(Arc::new(5))")
85 fn test_match_option_empty_string() {
86 let a = Some(String::new());
88 None => panic!("unexpected None while matching on Some(String::new())"),
94 fn test_match_option_string() {
95 let five = "Five".to_string();
97 Some(s) => assert_eq!(s, "Five"),
98 None => panic!("unexpected None while matching on Some(String { ... })")