diff options
author | iximeow <me@iximeow.net> | 2024-05-13 23:39:50 -0700 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2024-05-13 23:40:30 -0700 |
commit | c21a5f2956d8e0fa3eace14661a8aed124c6e995 (patch) | |
tree | d15a835dd75a5c140fd822df2c3102572243d9b5 /tests | |
parent | 1e9cf24e4ceca8bfd48ff3e6f777fcec54b9a186 (diff) |
test no-default-features more precisely0.2.8
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/lib.rs b/tests/lib.rs index 1d5e964..9dc1449 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -12,6 +12,7 @@ fn test_u16() { } #[test] +#[cfg(std)] fn generic_error_can_bail() { use yaxpeax_arch::{Arch, Decoder, Reader}; @@ -23,6 +24,7 @@ fn generic_error_can_bail() { } } #[test] +#[cfg(std)] fn error_can_bail() { use yaxpeax_arch::{Arch, AddressDiff, Decoder, Reader, LengthedInstruction, Instruction, StandardDecodeError, U8Reader}; struct TestIsa {} @@ -76,3 +78,51 @@ fn error_can_bail() { assert_eq!(exercise_eq(), Err(Error::TestDecode(StandardDecodeError::ExhaustedInput))); } + +#[test] +fn example_arch_impl() { + use yaxpeax_arch::{Arch, AddressDiff, Decoder, Reader, LengthedInstruction, Instruction, StandardDecodeError, U8Reader}; + struct TestIsa {} + #[derive(Debug, Default)] + struct TestInst {} + impl Arch for TestIsa { + type Word = u8; + type Address = u64; + type Instruction = TestInst; + type Decoder = TestIsaDecoder; + type DecodeError = StandardDecodeError; + type Operand = (); + } + + impl Instruction for TestInst { + fn well_defined(&self) -> bool { true } + } + + impl LengthedInstruction for TestInst { + type Unit = AddressDiff<u64>; + fn len(&self) -> Self::Unit { AddressDiff::from_const(1) } + fn min_size() -> Self::Unit { AddressDiff::from_const(1) } + } + + struct TestIsaDecoder {} + + impl Default for TestIsaDecoder { + fn default() -> Self { + TestIsaDecoder {} + } + } + + impl Decoder<TestIsa> for TestIsaDecoder { + fn decode_into<T: Reader<u64, u8>>(&self, _inst: &mut TestInst, _words: &mut T) -> Result<(), StandardDecodeError> { + Err(StandardDecodeError::ExhaustedInput) + } + } + + fn exercise_eq() -> Result<(), StandardDecodeError> { + let mut reader = U8Reader::new(&[]); + TestIsaDecoder::default().decode(&mut reader)?; + Ok(()) + } + + assert_eq!(exercise_eq(), Err(StandardDecodeError::ExhaustedInput)); +} |