1 use core::num::{NonZeroU32, NonZeroI32};
2 use core::option::Option;
3 use core::option::Option::{Some, None};
7 fn test_create_nonzero_instance() {
9 NonZeroU32::new_unchecked(21)
14 fn test_size_nonzero_in_option() {
15 assert_eq!(size_of::<NonZeroU32>(), size_of::<Option<NonZeroU32>>());
16 assert_eq!(size_of::<NonZeroI32>(), size_of::<Option<NonZeroI32>>());
20 fn test_match_on_nonzero_option() {
22 NonZeroU32::new_unchecked(42)
25 Some(val) => assert_eq!(val.get(), 42),
26 None => panic!("unexpected None while matching on Some(NonZeroU32(_))")
29 match unsafe { Some(NonZeroU32::new_unchecked(43)) } {
30 Some(val) => assert_eq!(val.get(), 43),
31 None => panic!("unexpected None while matching on Some(NonZeroU32(_))")
36 fn test_match_option_empty_vec() {
37 let a: Option<Vec<isize>> = Some(vec![]);
39 None => panic!("unexpected None while matching on Some(vec![])"),
45 fn test_match_option_vec() {
46 let a = Some(vec![1, 2, 3, 4]);
48 Some(v) => assert_eq!(v, [1, 2, 3, 4]),
49 None => panic!("unexpected None while matching on Some(vec![1, 2, 3, 4])")
54 fn test_match_option_rc() {
57 let five = Rc::new(5);
59 Some(r) => assert_eq!(*r, 5),
60 None => panic!("unexpected None while matching on Some(Rc::new(5))")
65 fn test_match_option_arc() {
68 let five = Arc::new(5);
70 Some(a) => assert_eq!(*a, 5),
71 None => panic!("unexpected None while matching on Some(Arc::new(5))")
76 fn test_match_option_empty_string() {
77 let a = Some(String::new());
79 None => panic!("unexpected None while matching on Some(String::new())"),
85 fn test_match_option_string() {
86 let five = "Five".to_string();
88 Some(s) => assert_eq!(s, "Five"),
89 None => panic!("unexpected None while matching on Some(String { ... })")
94 use core::num::NonZeroU32;
96 #[derive(PartialEq, Eq)]
98 index: NonZeroU32, // private
100 pub const FOO_ATOM: Atom = Atom { index: unsafe { NonZeroU32::new_unchecked(7) } };
104 ("foo") => { atom::FOO_ATOM }
108 fn test_match_nonzero_const_pattern() {
110 // Using as a pattern is supported by the compiler:
112 _ => panic!("Expected the const item as a pattern to match.")
117 fn test_from_nonzero() {
118 let nz = NonZeroU32::new(1).unwrap();
119 let num: u32 = nz.into();
120 assert_eq!(num, 1u32);
124 fn test_from_signed_nonzero() {
125 let nz = NonZeroI32::new(1).unwrap();
126 let num: i32 = nz.into();
127 assert_eq!(num, 1i32);