Skip to content

Commit

Permalink
Add test from issue 371
Browse files Browse the repository at this point in the history
  • Loading branch information
wcampbell0x2a committed Jan 11, 2024
1 parent 62c1ddb commit 32d4588
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/bit_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,39 @@ fn test_bit_order_little() {
let bytes = bit_order_little.to_bytes().unwrap();
assert_eq_hex!(bytes, data);
}

#[test]
fn test_bit_order_13() {
#[derive(DekuRead, PartialEq, Debug)]
#[deku(bit_order = "lsb")]
pub struct BitTest {
#[deku(bits = "13")]
raw_value1: u16,
#[deku(bits = "13")]
raw_value2: u16,
#[deku(bits = "6")]
raw_value3: u16,
}

let data = vec![0b00000000, 0b00000010, 0b01000000, 0b00000000];

let string_data = data
.iter()
.map(|f| (format!("{:08b}", f).chars().rev().collect()))
.collect::<Vec<String>>()
.join("");

println!("string_data: {}", string_data);

assert_eq!(string_data[0..13], string_data[13..26]);
assert_eq!(string_data.chars().nth(9).unwrap(), '1');

assert_eq!(
BitTest {
raw_value1: 2_u16.pow(9),
raw_value2: 2_u16.pow(9),
raw_value3: 0
},
BitTest::try_from(data.as_slice()).unwrap()
);
}

0 comments on commit 32d4588

Please sign in to comment.