diff options
Diffstat (limited to 'third_party/rust/derive_more/tests/unwrap.rs')
-rw-r--r-- | third_party/rust/derive_more/tests/unwrap.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/third_party/rust/derive_more/tests/unwrap.rs b/third_party/rust/derive_more/tests/unwrap.rs new file mode 100644 index 0000000000..ec84f7de96 --- /dev/null +++ b/third_party/rust/derive_more/tests/unwrap.rs @@ -0,0 +1,62 @@ +#![allow(dead_code)] + +#[macro_use] +extern crate derive_more; + +#[derive(Unwrap)] +enum Either<TLeft, TRight> { + Left(TLeft), + Right(TRight), +} + +#[derive(Unwrap)] +enum Maybe<T> { + Nothing, + Just(T), +} + +#[derive(Unwrap)] +enum Color { + RGB(u8, u8, u8), + CMYK(u8, u8, u8, u8), +} + +#[derive(Unwrap)] +enum Nonsense<'a, T> { + Ref(&'a T), + NoRef, + #[unwrap(ignore)] + NoRefIgnored, +} + +#[derive(Unwrap)] +enum WithConstraints<T> +where + T: Copy, +{ + One(T), + Two, +} +#[derive(Unwrap)] +enum KitchenSink<'a, 'b, T1: Copy, T2: Clone> +where + T2: Into<T1> + 'b, +{ + Left(&'a T1), + Right(&'b T2), + OwnBoth(T1, T2), + Empty, + NeverMind(), + NothingToSeeHere(), +} + +#[test] +pub fn test_unwrap() { + assert_eq!(Maybe::<()>::Nothing.unwrap_nothing(), ()); +} + +#[test] +#[should_panic] +pub fn test_unwrap_panic() { + Maybe::<()>::Nothing.unwrap_just() +} |