Skip to content

Commit

Permalink
test: fix doctests for 32-bit and 16-bit pointer widths
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Jul 17, 2024
1 parent eba9730 commit a2ef25d
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,35 @@ macro_rules! impl_sum_product {

impl_sum_product! { Xe<i8> Xe<i16> Xe<i32> Xe<i64> Xe<i128> Xe<isize> Xe<u8> Xe<u16> Xe<u32> Xe<u64> Xe<u128> Xe<usize> }

#[cfg(target_pointer_width = "16")]
macro_rules! usize_macro {
($macro:ident) => {
$macro!(u16)
};
}

#[cfg(target_pointer_width = "32")]
macro_rules! usize_macro {
($macro:ident) => {
$macro!(u32)
};
}

#[cfg(target_pointer_width = "64")]
macro_rules! usize_macro {
($macro:ident) => {
$macro!(u64)
};
}

#[rustfmt::skip]
macro_rules! rot {
(u8) => { 2 };
(u16) => { 4 };
(u32) => { 8 };
(u64) => { 12 };
(u128) => { 16 };
(usize) => { rot!(u64) };
(usize) => { usize_macro!(rot) };
(i8) => { rot!(u8) };
(i16) => { rot!(u16) };
(i32) => { rot!(u32) };
Expand All @@ -575,7 +596,7 @@ macro_rules! rot_op {
(u32) => { "0x10000b3" };
(u64) => { "0xaa00000000006e1" };
(u128) => { "0x13f40000000000000000000000004f76" };
(usize) => { rot_op!(u64) };
(usize) => { usize_macro!(rot_op) };
(i8) => { "-0x7e" };
(i16) => { "-0x5ffd" };
(i32) => { rot_op!(u32) };
Expand All @@ -591,7 +612,7 @@ macro_rules! rot_result {
(u32) => { "0xb301" };
(u64) => { "0x6e10aa" };
(u128) => { "0x4f7613f4" };
(usize) => { rot_result!(u64) };
(usize) => { usize_macro!(rot_result) };
(i8) => { rot_result!(u8) };
(i16) => { rot_result!(u16) };
(i32) => { rot_result!(u32) };
Expand All @@ -607,7 +628,7 @@ macro_rules! swap_op {
(u32) => { "0x12345678" };
(u64) => { "0x1234567890123456" };
(u128) => { "0x12345678901234567890123456789012" };
(usize) => { swap_op!(u64) };
(usize) => { usize_macro!(swap_op) };
(i8) => { swap_op!(u8) };
(i16) => { swap_op!(u16) };
(i32) => { swap_op!(u32) };
Expand All @@ -623,7 +644,7 @@ macro_rules! swapped {
(u32) => { "0x78563412" };
(u64) => { "0x5634129078563412" };
(u128) => { "0x12907856341290785634129078563412" };
(usize) => { swapped!(u64) };
(usize) => { usize_macro!(swapped) };
(i8) => { swapped!(u8) };
(i16) => { swapped!(u16) };
(i32) => { swapped!(u32) };
Expand All @@ -639,7 +660,7 @@ macro_rules! reversed {
(u32) => { "0x1e6a2c48" };
(u64) => { "0x6a2c48091e6a2c48" };
(u128) => { "0x48091e6a2c48091e6a2c48091e6a2c48" };
(usize) => { reversed!(u64) };
(usize) => { usize_macro!(reversed) };
(i8) => { reversed!(u8) };
(i16) => { reversed!(u16) };
(i32) => { reversed!(u32) };
Expand All @@ -654,7 +675,7 @@ macro_rules! be_bytes {
(u32) => { "[0x12, 0x34, 0x56, 0x78]" };
(u64) => { "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]" };
(u128) => { "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12]" };
(usize) => { be_bytes!(u64) };
(usize) => { usize_macro!(be_bytes) };
(i8) => { be_bytes!(u8) };
(i16) => { be_bytes!(u16) };
(i32) => { be_bytes!(u32) };
Expand All @@ -669,7 +690,7 @@ macro_rules! le_bytes {
(u32) => { "[0x78, 0x56, 0x34, 0x12]" };
(u64) => { "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]" };
(u128) => { "[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]" };
(usize) => { le_bytes!(u64) };
(usize) => { usize_macro!(le_bytes) };
(i8) => { le_bytes!(u8) };
(i16) => { le_bytes!(u16) };
(i32) => { le_bytes!(u32) };
Expand Down

0 comments on commit a2ef25d

Please sign in to comment.