Implements mocking for MoveData
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-11-27 23:00:56 +01:00
parent ad9f17ccf1
commit d4b1cadad0
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 29 additions and 13 deletions

View File

@ -67,3 +67,4 @@ serde_json = "1.0.81"
serde_plain = "1.0.0"
# Allow us to assert whether floats are approximately a value
assert_approx_eq = "1.1.0"
mockall = "0.11.2"

View File

@ -100,22 +100,13 @@ impl ValueIdentifiable for LearnedMove {
#[cfg(test)]
mod tests {
use super::*;
use crate::static_data::{MoveCategory, MoveDataImpl, MoveTarget};
use crate::static_data::MockMoveData;
#[test]
fn create_learned_move_restore_uses() {
let data: Arc<dyn MoveData> = Arc::new(MoveDataImpl::new(
&"foo".into(),
0u8.into(),
MoveCategory::Special,
100,
20,
30,
MoveTarget::All,
0,
None,
Default::default(),
));
let mut mock = MockMoveData::new();
mock.expect_base_usages().return_const(30);
let data: Arc<dyn MoveData> = Arc::new(mock);
let learned_move = LearnedMove::new(&data, MoveLearnMethod::Level);
assert!(learned_move.try_use(15));
learned_move.restore_uses(5);

View File

@ -206,3 +206,27 @@ impl ValueIdentifiable for MoveDataImpl {
self.identifier
}
}
#[cfg(test)]
mockall::mock! {
#[derive(Debug)]
pub MoveData{}
impl MoveData for MoveData {
fn name(&self) -> &StringKey;
fn move_type(&self) -> TypeIdentifier;
fn category(&self) -> MoveCategory;
fn base_power(&self) -> u8;
fn accuracy(&self) -> u8;
fn base_usages(&self) -> u8;
fn target(&self) -> MoveTarget;
fn priority(&self) -> i8;
fn secondary_effect(&self) -> &Option<Box<dyn SecondaryEffect>>;
fn has_flag(&self, key: &StringKey) -> bool;
fn has_flag_by_hash(&self, key_hash: u32) -> bool;
}
impl ValueIdentifiable for MoveData{
fn value_identifier(&self) -> ValueIdentifier{
ValueIdentifier::new(0)
}
}
}