macro_rules! test_encoding_enum {
    ($enum:path as $ty:ty; $( $item:path => $val:expr ),+) => { ... };
    ($se:ident => $enum:path as $ty:ty; $( $item:path => $val:expr ),+) => { ... };
}
Expand description

Macro testing encodings of all enum variants.

NB: If the enum has primitive assigned values, test_encoding_enum_by_values should be used instead if this macro. If primitive values are u8-based, please use test_encoding_enum_u8_exhaustive.

Macro expands into an expression of Result<(), EnumEncodingTestFailure> type.

Covered test case

  • Strict encoding must match little-endian encoding of the value
  • Roundtrip encoding-decoding of the enum variant must result in the original value

Example


#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
#[repr(u8)]
#[derive(StrictEncode, StrictDecode)]
#[strict_encoding(repr = u8)]
enum Bits {
    #[strict_encoding(value = 8)]
    Bit8,

    #[strict_encoding(value = 16)]
    Bit16,
}

test_encoding_enum!(
    Bits as u8;
    Bits::Bit8 => 8_u8, Bits::Bit16 => 16_u8
).unwrap();