And full(ish) test coverage

This commit is contained in:
Reid 'arrdem' McKenzie 2022-12-24 01:25:49 -07:00
parent 6ea80dd3d2
commit 51d6cdd3b1
2 changed files with 67 additions and 1 deletions

View file

@ -28,7 +28,7 @@ pub trait Device: std::fmt::Debug {
fn deo2(&mut self, vm: &mut Uxn, port: u8, val: u16) -> Result<(), DeviceError> {
let slot = port & 0xF;
if slot < 0xF {
if slot == 0xF {
return Err(DeviceError::AddressOverflow);
}
let [high, low] = val.to_be_bytes();

View file

@ -1,3 +1,7 @@
use std::cell::RefCell;
use std::rc::Rc;
use uxn::device::buff::BuffDevice;
use uxn::isa::Icode;
use uxn::vm::*;
@ -714,6 +718,68 @@ fn test_sta2() {
assert_eq!(vm.lda2(0x010c), Ok(0xFFEE));
}
#[test]
fn test_dei() {
nofmt::pls! {
let mut vm = Uxn::of1(&[
Icode::LIT, 0x30, Icode::DEI, Icode::BRK,
]);
let dev = Rc::new(RefCell::new(BuffDevice::new()));
vm.deo1(0x30, 0xFF).unwrap();
vm.deo1(0x31, 0xEE).unwrap();
vm.devices[3] = dev.clone();
}
assert_eq!(vm.run(64), Err(UxnError::Break));
assert_eq!(vm.wst.borrow().idx(), 1);
assert_eq!(vm.wst.borrow().peek1(), Ok(0xFF));
}
#[test]
fn test_dei2() {
nofmt::pls! {
let mut vm = Uxn::of1(&[
Icode::LIT, 0x30, Icode::DEI | Icode::SHORT, Icode::BRK,
]);
let dev = Rc::new(RefCell::new(BuffDevice::new()));
vm.deo2(0x30, 0xFFEE).unwrap();
vm.devices[3] = dev.clone();
}
assert_eq!(vm.run(64), Err(UxnError::Break));
assert_eq!(vm.wst.borrow().idx(), 2);
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFFEE));
}
#[test]
fn test_deo() {
nofmt::pls! {
let mut vm = Uxn::of1(&[
Icode::LIT | Icode::SHORT, 0xFF, 0x30, Icode::DEO, Icode::BRK,
]);
let dev = Rc::new(RefCell::new(BuffDevice::new()));
vm.devices[3] = dev.clone();
}
assert_eq!(vm.run(64), Err(UxnError::Break));
assert_eq!(vm.wst.borrow().idx(), 0);
assert_eq!(vm.dei1(0x30), Ok(0xFF));
}
#[test]
fn test_deo2() {
nofmt::pls! {
let mut vm = Uxn::of1(&[
Icode::LIT | Icode::SHORT, 0xFF, 0xEE,
Icode::LIT, 0x30,
Icode::DEO | Icode::SHORT,
Icode::BRK,
]);
let dev = Rc::new(RefCell::new(BuffDevice::new()));
vm.devices[3] = dev.clone();
}
assert_eq!(vm.run(64), Err(UxnError::Break));
assert_eq!(vm.wst.borrow().idx(), 0);
assert_eq!(vm.dei2(0x30), Ok(0xFFEE));
}
#[test]
fn test_add() {
nofmt::pls! {