]>
Witch of Git - jade-mouse/blob - toolchain/src/inst/test.rs
1 use super::{Cond
, Decode
, Encode
, Inst
, Reg
};
2 use proptest
::prelude
::*;
5 pub(super) fn cond_strategy(op
: impl Fn(Reg
, Reg
) -> Cond
) -> impl Strategy
<Value
= Cond
> {
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 cursor
.set_position(0);
26 let out_inst
= Inst
::decode(&mut cursor
)
27 .expect(&format
!("Should decode instruction bytes {:?}", cursor
.get_ref()));
28 prop_assert_eq
!(inst
, out_inst
, "inst should round-trip the same");