| 1 | #![warn( |
| 2 | clippy::default_trait_access, |
| 3 | clippy::dbg_macro, |
| 4 | clippy::print_stdout, |
| 5 | clippy::unimplemented, |
| 6 | clippy::use_self, |
| 7 | missing_copy_implementations, |
| 8 | missing_docs, |
| 9 | non_snake_case, |
| 10 | non_upper_case_globals, |
| 11 | rust_2018_idioms, |
| 12 | unreachable_pub |
| 13 | )] |
| 14 | |
| 15 | use enum_as_inner::EnumAsInner; |
| 16 | |
| 17 | pub mod name_collisions { |
| 18 | #![allow(dead_code, missing_copy_implementations, missing_docs)] |
| 19 | pub struct Option; |
| 20 | pub struct Some; |
| 21 | pub struct None; |
| 22 | pub struct Result; |
| 23 | pub struct Ok; |
| 24 | pub struct Err; |
| 25 | } |
| 26 | #[allow(unused_imports)] |
| 27 | use name_collisions::*; |
| 28 | |
| 29 | #[derive(Debug, EnumAsInner)] |
| 30 | enum EmptyTest {} |
| 31 | |
| 32 | #[test] |
| 33 | fn test_empty() { |
| 34 | let empty = std::option::Option::None::<EmptyTest>; |
| 35 | |
| 36 | assert!(empty.is_none()); |
| 37 | } |
| 38 | |
| 39 | #[derive(Debug, EnumAsInner)] |
| 40 | enum EmptyParendsTest { |
| 41 | Empty(), |
| 42 | } |
| 43 | |
| 44 | #[test] |
| 45 | fn test_empty_parends() { |
| 46 | let mut empty = EmptyParendsTest::Empty(); |
| 47 | |
| 48 | assert!(empty.is_empty()); |
| 49 | |
| 50 | empty |
| 51 | .as_empty() |
| 52 | .expect("should have been something and a unit"); |
| 53 | empty |
| 54 | .as_empty_mut() |
| 55 | .expect("should have been something and a unit"); |
| 56 | |
| 57 | empty |
| 58 | .into_empty() |
| 59 | .expect("should have been something and a unit"); |
| 60 | } |
| 61 | |
| 62 | #[derive(Debug, EnumAsInner)] |
| 63 | enum OneTest { |
| 64 | One(u32), |
| 65 | } |
| 66 | |
| 67 | #[test] |
| 68 | fn test_one() { |
| 69 | let mut empty = OneTest::One(1); |
| 70 | |
| 71 | assert!(empty.is_one()); |
| 72 | assert_eq!(*empty.as_one().unwrap(), 1); |
| 73 | assert_eq!(*empty.as_one_mut().unwrap(), 1); |
| 74 | assert_eq!(empty.into_one().unwrap(), 1); |
| 75 | } |
| 76 | |
| 77 | #[derive(Debug, EnumAsInner)] |
| 78 | enum MultiTest { |
| 79 | Multi(u32, u32), |
| 80 | } |
| 81 | |
| 82 | #[test] |
| 83 | fn test_multi() { |
| 84 | let mut multi = MultiTest::Multi(1, 1); |
| 85 | |
| 86 | assert!(multi.is_multi()); |
| 87 | assert_eq!(multi.as_multi().unwrap(), (&1_u32, &1_u32)); |
| 88 | assert_eq!(multi.as_multi_mut().unwrap(), (&mut 1_u32, &mut 1_u32)); |
| 89 | assert_eq!(multi.into_multi().unwrap(), (1_u32, 1_u32)); |
| 90 | } |