aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2021-07-03 21:55:23 -0700
committeriximeow <me@iximeow.net>2021-07-03 21:55:23 -0700
commit288ab8fa823d2fbe567e60253c8bad9b2c9b7fd4 (patch)
tree51d3fd061bc5199f85503353e178c7f56cc228b5 /tests
parentb49987bdbd2b5a08163a45ef3dc1868754d84165 (diff)
support std::error::Error
included is mandataing a `description` method on `DecodeError` implementors - already approximately required by the Debug and Display anyway. also include a StandardPartialDecoderError for incomplete decoders to use. i expect that one of the last steps of a decoder's 1.0 release will be to move away from this.
Diffstat (limited to 'tests')
-rw-r--r--tests/lib.rs57
1 files changed, 55 insertions, 2 deletions
diff --git a/tests/lib.rs b/tests/lib.rs
index 15477f7..8e097de 100644
--- a/tests/lib.rs
+++ b/tests/lib.rs
@@ -1,5 +1,3 @@
-#![no_std]
-
use yaxpeax_arch::AddressBase;
#[test]
@@ -10,3 +8,58 @@ fn test_u16() {
}
}
}
+
+#[test]
+fn error_can_bail() {
+ 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)
+ }
+ }
+
+ #[derive(Debug, PartialEq, thiserror::Error)]
+ pub enum Error {
+ #[error("decode error")]
+ TestDecode(#[from] StandardDecodeError),
+ }
+
+ fn exercise_eq() -> Result<(), Error> {
+ let mut reader = U8Reader::new(&[]);
+ TestIsaDecoder::default().decode(&mut reader)?;
+ Ok(())
+ }
+
+ assert_eq!(exercise_eq(), Err(Error::TestDecode(StandardDecodeError::ExhaustedInput)));
+}