diff --git a/packed_struct_tests/tests/packing_bit_positioning.rs b/packed_struct_tests/tests/packing_bit_positioning.rs index 766cf82..8245943 100644 --- a/packed_struct_tests/tests/packing_bit_positioning.rs +++ b/packed_struct_tests/tests/packing_bit_positioning.rs @@ -60,6 +60,33 @@ fn test_packing_bit_positions_lsb() { } +#[derive(PackedStruct, PartialEq, Debug)] +#[packed_struct(size_bytes="4", bit_numbering="lsb0", endian="lsb")] +pub struct BigIntsLsb { + #[packed_field(bits="26:24")] + pub val1: Integer, + #[packed_field(bits="18")] + pub val2: bool, + #[packed_field(bits="15:0")] + pub val3: Integer, +} + +#[test] +/// This test should verify the packing/unpacking a hypothetical 32-bit register that contains 0xbeef0407 +fn test_packing_bit_positions_bigints_lsb() { + let a = BigIntsLsb { + val1: 7.into(), + val2: true, + val3: 0xbeef.into(), + }; + + let packed = a.pack(); + assert_eq!(&[0x07u8, 0x04, 0xef, 0xbe], &packed, "mismatch received: {}", a); + + let unpacked = BigIntsLsb::unpack(&packed).unwrap(); + assert_eq!(a, unpacked); +} + #[test] fn test_packing_byte_position() {