Skip to content

Commit

Permalink
Add a few more tests for data-carrying enums
Browse files Browse the repository at this point in the history
  • Loading branch information
djkoloski committed Feb 15, 2024
1 parent 2102f0e commit a9842ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions zerocopy-derive/tests/enum_from_zeros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions zerocopy-derive/tests/enum_try_from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,6 @@ fn test_has_fields() {
const SIZE: usize = core::mem::size_of::<HasFields>();
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 }));
}

0 comments on commit a9842ca

Please sign in to comment.