From a9842cab4362554c3ce284245cb279b0375610c6 Mon Sep 17 00:00:00 2001 From: David Koloski Date: Thu, 15 Feb 2024 16:29:19 -0500 Subject: [PATCH] Add a few more tests for data-carrying enums --- zerocopy-derive/tests/enum_from_zeros.rs | 9 +++++++++ zerocopy-derive/tests/enum_try_from_bytes.rs | 2 ++ 2 files changed, 11 insertions(+) diff --git a/zerocopy-derive/tests/enum_from_zeros.rs b/zerocopy-derive/tests/enum_from_zeros.rs index df64e4d240..abe30dcb74 100644 --- a/zerocopy-derive/tests/enum_from_zeros.rs +++ b/zerocopy-derive/tests/enum_from_zeros.rs @@ -36,3 +36,12 @@ enum Baz { } assert_impl_all!(Baz: FromZeros); + +#[derive(FromZeros)] +#[repr(C)] +enum Bat { + A(u32), + B { foo: u32 }, +} + +assert_impl_all!(Bat: FromZeros); diff --git a/zerocopy-derive/tests/enum_try_from_bytes.rs b/zerocopy-derive/tests/enum_try_from_bytes.rs index 3a9b24223c..ead433ede6 100644 --- a/zerocopy-derive/tests/enum_try_from_bytes.rs +++ b/zerocopy-derive/tests/enum_try_from_bytes.rs @@ -158,4 +158,6 @@ fn test_has_fields() { const SIZE: usize = core::mem::size_of::(); let bytes: [u8; SIZE] = zerocopy::transmute!(HasFields::B(10)); assert_eq!(HasFields::try_read_from(&bytes[..]), Some(HasFields::B(10))); + let bytes: [u8; SIZE] = zerocopy::transmute!(HasFields::C { foo: 10 }); + assert_eq!(HasFields::try_read_from(&bytes[..]), Some(HasFields::C { foo: 10 })); }