]>
Witch of Git - jade-mouse/blob - toolchain/src/inst/test.rs
efe1b5ed3c172e13dc0976a8527dd54296552d85
1 use super::{Cond
, Decode
, Encode
, Inst
, Reg
};
2 use proptest
::prelude
::*;
3 use std
::{fmt
::Debug
, io
::Cursor
};
5 pub(super) fn regpair
<T
: Debug
>(op
: impl Fn(Reg
, Reg
) -> T
) -> impl Strategy
<Value
= T
> {
6 (0..4u8, 1..4u8).prop_map(move |(a
, b
)| op(reg_num(a
), reg_num(a
+ b
)))
9 fn reg_num(x
: u8) -> Reg
{
21 fn encoding_roundtrip(inst
: Inst
) {
22 let mut buffer
= [0, 0];
23 let mut cursor
= Cursor
::new(&mut buffer
[..]);
24 inst
.encode(&mut cursor
).expect("Should encode instruction");
25 let len
= cursor
.position();
26 cursor
.set_position(0);
27 let out_inst
= Inst
::decode(&mut cursor
)
28 .expect(&format
!("Should decode instruction bytes {:?}", cursor
.get_ref()));
29 let buffer
= &buffer
[..len
as usize];
30 prop_assert_eq
!(inst
, out_inst
, "inst should round-trip the same. Encoded as {:x?}", buffer
);