A bunch of unit tests for assist
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
use crate::app_interface::Party;
|
||||
use alloc::rc::Rc;
|
||||
|
||||
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
||||
pub trait BattlePartyTrait {
|
||||
fn party(&self) -> Party;
|
||||
}
|
||||
|
||||
pub type BattleParty = Rc<dyn BattlePartyTrait>;
|
||||
#[cfg(feature = "mock_data")]
|
||||
pub type MockBattleParty = MockBattlePartyTrait;
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
mod implementation {
|
||||
|
||||
@@ -11,6 +11,7 @@ pub enum MoveLearnMethod {
|
||||
Level = 1,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
||||
pub trait LearnedMoveTrait {
|
||||
fn move_data(&self) -> MoveData;
|
||||
fn learn_method(&self) -> MoveLearnMethod;
|
||||
@@ -19,6 +20,8 @@ pub trait LearnedMoveTrait {
|
||||
}
|
||||
|
||||
pub type LearnedMove = Rc<dyn LearnedMoveTrait>;
|
||||
#[cfg(feature = "mock_data")]
|
||||
pub type MockLearnedMove = MockLearnedMoveTrait;
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
mod implementation {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use crate::app_interface::Pokemon;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::rc::Rc;
|
||||
use core::iter::IntoIterator;
|
||||
|
||||
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
||||
pub trait PartyTrait {
|
||||
fn get_pokemon(&self, index: usize) -> Option<Pokemon>;
|
||||
fn length(&self) -> usize;
|
||||
@@ -8,6 +11,18 @@ pub trait PartyTrait {
|
||||
|
||||
pub type Party = Rc<dyn PartyTrait>;
|
||||
|
||||
impl<'a> IntoIterator for &'a dyn PartyTrait {
|
||||
type Item = Option<Pokemon>;
|
||||
type IntoIter = ExternIterator<'a, Self::Item>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
ExternIterator::new(self.length(), Box::new(move |i| self.get_pokemon(i)))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mock_data")]
|
||||
pub type MockParty = MockPartyTrait;
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
mod implementation {
|
||||
use super::*;
|
||||
@@ -54,5 +69,6 @@ mod implementation {
|
||||
}
|
||||
}
|
||||
|
||||
use crate::utils::ExternIterator;
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
pub use implementation::*;
|
||||
|
||||
@@ -36,6 +36,7 @@ impl TurnChoice {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
||||
pub trait BaseTurnChoiceDataTrait {
|
||||
fn reference(&self) -> u32;
|
||||
fn user(&self) -> Pokemon;
|
||||
@@ -45,15 +46,20 @@ pub trait BaseTurnChoiceDataTrait {
|
||||
}
|
||||
|
||||
pub type BaseTurnChoiceData = Rc<dyn BaseTurnChoiceDataTrait>;
|
||||
#[cfg(feature = "mock_data")]
|
||||
pub type MockBaseTurnChoiceData = MockBaseTurnChoiceDataTrait;
|
||||
|
||||
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
||||
pub trait MoveTurnChoiceDataTrait {
|
||||
fn base(&self) -> BaseTurnChoiceData;
|
||||
fn used_move(&self) -> LearnedMove;
|
||||
fn target_side(&self) -> u8;
|
||||
fn target_index(&self) -> u8;
|
||||
fn priority(&self) -> i8;
|
||||
fn move_script(&self) -> Option<&Box<dyn Script>>;
|
||||
fn move_script<'a>(&self) -> Option<&'a Box<dyn Script>>;
|
||||
}
|
||||
#[cfg(feature = "mock_data")]
|
||||
pub type MockMoveTurnChoiceData = MockMoveTurnChoiceDataTrait;
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
mod implementation {
|
||||
|
||||
@@ -29,6 +29,7 @@ pub enum MoveTarget {
|
||||
OnSelf,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
||||
pub trait MoveDataTrait {
|
||||
fn name(&self) -> StringKey;
|
||||
fn move_type(&self) -> u8;
|
||||
@@ -42,6 +43,8 @@ pub trait MoveDataTrait {
|
||||
}
|
||||
|
||||
pub type MoveData = Rc<dyn MoveDataTrait>;
|
||||
#[cfg(feature = "mock_data")]
|
||||
pub type MockMoveData = MockMoveDataTrait;
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
mod implementation {
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::handling::Cacheable;
|
||||
use crate::{ExternRef, ExternalReferenceType};
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
use core::fmt::{Display, Formatter};
|
||||
use core::fmt::{Debug, Display, Formatter};
|
||||
use cstr_core::CString;
|
||||
|
||||
struct StringKeyInner {
|
||||
@@ -19,6 +19,12 @@ pub struct StringKey {
|
||||
data: Rc<StringKeyInner>,
|
||||
}
|
||||
|
||||
impl Debug for StringKey {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "\"{}\"", self.str().to_str().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl StringKey {
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
pub(crate) fn new(ptr: ExternRef<Self>) -> Self {
|
||||
@@ -185,4 +191,10 @@ mod test {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for StringKey {
|
||||
fn from(value: &str) -> Self {
|
||||
StringKey::new(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use alloc::boxed::Box;
|
||||
|
||||
#[macro_export]
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
macro_rules! println { ($($args:tt)*) => { crate::utils::print_raw(alloc::format!($($args)*).as_bytes()); } }
|
||||
@@ -77,3 +79,33 @@ mod implementation {
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
pub use implementation::*;
|
||||
|
||||
pub struct ExternIterator<'a, T> {
|
||||
len: usize,
|
||||
index: usize,
|
||||
getter: Box<dyn Fn(usize) -> T + 'a>,
|
||||
}
|
||||
|
||||
impl<'a, T> ExternIterator<'a, T> {
|
||||
pub fn new(len: usize, f: Box<dyn Fn(usize) -> T + 'a>) -> Self {
|
||||
Self {
|
||||
len,
|
||||
index: 0,
|
||||
getter: f,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator for ExternIterator<'a, T> {
|
||||
type Item = T;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let index = self.index;
|
||||
if index >= self.len {
|
||||
None
|
||||
} else {
|
||||
self.index += 1;
|
||||
Some((self.getter)(index))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user