Macro strict_encoding::test_encoding_enum_u8_exhaustive [−][src]
macro_rules! test_encoding_enum_u8_exhaustive { ($enum:path; $( $item:path => $val:expr ),+) => { ... }; ($enum:path as $ty:ty; $( $item:path => $val:expr ),+) => { ... }; ($se:ident => $enum:path; $( $item:path => $val:expr ),+) => { ... }; ($se:ident => $enum:path as $ty:ty; $( $item:path => $val:expr ),+) => { ... }; }
Expand description
Macro testing encoding of all possible enum values, covering full range of
u8
values, including enum out-of-range values.
Macro expands into an expression of Result<(),
EnumEncodingTestFailure
>
type.
Macro extends functionality of test_encoding_enum_by_values
and should
be used whenever enum with assigned primitive values is represented by u8
integers.
Covered test cases
- Each enum variant must have a primitive value
- Primitive value representing enum variant must be equal to strict encoding
of the same variant. If a primitive enum value occupies of several bytes
(
u16
,u32
and other large integer types), strict encoding must match little-endian encoding of the value - Roundtrip encoding-decoding of the enum variant must result in the original value
- Each enum variant must be equal to itself
- Each enum variant must not be equal to any other enum variant
- Enum variants must be ordered according to their primitive values
- All 8-bit integers which do not match any of enum variants must not be
decoded with strict decoder into a valid enum and their decoding must
result in
Error::EnumValueNotKnown
error.
Example
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)] #[repr(u8)] #[derive(StrictEncode, StrictDecode)] #[strict_encoding(repr = u8, by_value)] enum Bits { Bit8 = 8, Bit16 = 16, } test_encoding_enum_u8_exhaustive!( Bits as u8; Bits::Bit8 => 8_u8, Bits::Bit16 => 16_u8 ).unwrap();