]> Witch of Git - jade-mouse/blob - toolchain/src/inst/test.rs
Add proptest encoding round-trip test
[jade-mouse] / toolchain / src / inst / test.rs
1 use super::{Decode, Encode, Inst};
2 use proptest::prelude::*;
3 use std::io::Cursor;
4
5 proptest! {
6 #[test]
7 fn encoding_roundtrip(inst: Inst) {
8 let mut buffer = [0, 0];
9 let mut cursor = Cursor::new(&mut buffer[..]);
10 inst.encode(&mut cursor).expect("Should encode instruction");
11 cursor.set_position(0);
12 let out_inst = Inst::decode(&mut cursor)
13 .expect(&format!("Should decode instruction bytes {:?}", cursor.get_ref()));
14 prop_assert_eq!(inst, out_inst, "inst should round-trip the same");
15 }
16 }