From 12bba22a456ed452efda8c951f61bdff1a516252 Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 6 Jul 2021 21:42:09 -0700 Subject: fix incorrect `offset` and `total_offset` counts for non-`u8` Word also update yaxpeax-arch to 0.2.4 --- tests/lib.rs | 2 ++ tests/reader.rs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/reader.rs (limited to 'tests') diff --git a/tests/lib.rs b/tests/lib.rs index 9add6e3..1d5e964 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,5 +1,7 @@ use yaxpeax_arch::AddressBase; +mod reader; + #[test] fn test_u16() { for l in 0..100 { diff --git a/tests/reader.rs b/tests/reader.rs new file mode 100644 index 0000000..d5d5440 --- /dev/null +++ b/tests/reader.rs @@ -0,0 +1,24 @@ +use yaxpeax_arch::{Reader, U8Reader, U16le, U32le}; + +#[test] +fn reader_offset_is_words_not_bytes() { + fn test_u16>(reader: &mut T) { + reader.mark(); + assert_eq!(reader.offset(), 0); + reader.next().unwrap(); + assert_eq!(reader.offset(), 1); + reader.mark(); + reader.next().unwrap(); + assert_eq!(reader.offset(), 1); + assert_eq!(reader.total_offset(), 2); + } + fn test_u32>(reader: &mut T) { + reader.mark(); + assert_eq!(reader.offset(), 0); + reader.next().unwrap(); + assert_eq!(reader.offset(), 1); + } + + test_u16(&mut U8Reader::new(&[0x01, 0x02, 0x03, 0x04])); + test_u32(&mut U8Reader::new(&[0x01, 0x02, 0x03, 0x04])); +} -- cgit v1.1