2022-06-17 17:53:33 +00:00
|
|
|
#![feature(custom_test_frameworks)]
|
|
|
|
#![feature(once_cell)]
|
|
|
|
#![test_runner(datatest::runner)]
|
2022-12-24 13:03:47 +00:00
|
|
|
#![allow(clippy::borrowed_box)]
|
2022-06-17 17:53:33 +00:00
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
|
|
|
use std::path::Path;
|
2022-08-20 10:22:12 +00:00
|
|
|
use std::sync::Arc;
|
2022-06-17 17:53:33 +00:00
|
|
|
|
2022-09-16 09:01:37 +00:00
|
|
|
use pkmn_lib::dynamic_data::{
|
|
|
|
Battle, BattleParty, DamageSource, DynamicLibrary, ExecutingMove, MoveChoice, PokemonBuilder, PokemonParty, Script,
|
|
|
|
ScriptCategory, ScriptContainer, ScriptOwnerData, TurnChoice, VolatileScriptsOwner,
|
|
|
|
};
|
|
|
|
use pkmn_lib::script_implementations::wasm::script::WebAssemblyScript;
|
2022-06-19 19:34:08 +00:00
|
|
|
|
|
|
|
use crate::common::{library_loader, TestCase};
|
|
|
|
|
2022-06-17 17:53:33 +00:00
|
|
|
pub mod common;
|
|
|
|
|
2022-12-24 11:00:50 +00:00
|
|
|
fn get_library() -> Arc<dyn DynamicLibrary> {
|
|
|
|
library_loader::load_library()
|
2022-07-18 08:16:47 +00:00
|
|
|
}
|
2022-06-17 17:53:33 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-09-17 10:11:09 +00:00
|
|
|
#[cfg_attr(miri, ignore)]
|
2022-06-17 17:53:33 +00:00
|
|
|
fn validate_library_load() {
|
2022-07-18 08:16:47 +00:00
|
|
|
let start_time = chrono::Utc::now();
|
2022-07-18 08:49:58 +00:00
|
|
|
library_loader::load_library();
|
2022-07-18 08:16:47 +00:00
|
|
|
let end_time = chrono::Utc::now();
|
|
|
|
println!("Built library in {} ms", (end_time - start_time).num_milliseconds());
|
2022-06-17 17:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[datatest::files("tests/test_cases", {
|
|
|
|
input in r"^(.*)\.yaml"
|
|
|
|
})]
|
2022-06-17 18:38:00 +00:00
|
|
|
#[cfg_attr(miri, ignore)]
|
2022-06-17 17:53:33 +00:00
|
|
|
fn integration_tests(input: &Path) {
|
|
|
|
let mut str: String = "".to_string();
|
|
|
|
let mut file = File::open(input).unwrap();
|
|
|
|
file.read_to_string(&mut str).unwrap();
|
2022-08-26 16:23:35 +00:00
|
|
|
let test_case = serde_yaml::from_str::<TestCase>(&str).unwrap();
|
2022-06-17 17:53:33 +00:00
|
|
|
println!("\tRunning integration test {}", test_case.name);
|
2022-07-18 08:16:47 +00:00
|
|
|
test_case.run_test(get_library());
|
|
|
|
}
|
2022-09-16 09:01:37 +00:00
|
|
|
|
|
|
|
/// Assurance has the interesting properties that it creates a special data script internally, and
|
|
|
|
/// deletes that data script through the get_owner functionality.
|
|
|
|
#[test]
|
|
|
|
#[cfg_attr(miri, ignore)]
|
|
|
|
fn validate_assurance() {
|
|
|
|
let lib = get_library();
|
|
|
|
let p1 = Arc::new(
|
|
|
|
PokemonBuilder::new(lib.clone(), "charizard".into(), 100)
|
|
|
|
.learn_move("assurance".into())
|
|
|
|
.build(),
|
|
|
|
);
|
|
|
|
let p2 = Arc::new(PokemonBuilder::new(lib.clone(), "venusaur".into(), 100).build());
|
|
|
|
|
|
|
|
let party1 = BattleParty::new(
|
|
|
|
Arc::new(PokemonParty::new_from_vec(vec![Some(p1.clone())])),
|
|
|
|
vec![(0, 0)],
|
|
|
|
);
|
|
|
|
let party2 = BattleParty::new(
|
|
|
|
Arc::new(PokemonParty::new_from_vec(vec![Some(p2.clone())])),
|
|
|
|
vec![(1, 0)],
|
|
|
|
);
|
|
|
|
|
|
|
|
let battle = Battle::new(lib.clone(), vec![party1, party2], false, 2, 1, None);
|
|
|
|
|
|
|
|
battle.sides()[0].set_pokemon(0, Some(p1.clone()));
|
|
|
|
battle.sides()[1].set_pokemon(0, Some(p2.clone()));
|
|
|
|
|
|
|
|
let script = lib
|
|
|
|
.load_script(ScriptOwnerData::None, ScriptCategory::Move, &"assurance".into())
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let mv = p1.learned_moves().read()[0].as_ref().unwrap().clone();
|
|
|
|
let choice = TurnChoice::Move(MoveChoice::new(p1.clone(), mv.clone(), 1, 0));
|
|
|
|
script.on_before_turn(&choice);
|
|
|
|
assert!(battle.sides()[1].has_volatile_script(&"assurance_data".into()));
|
|
|
|
|
|
|
|
let executing_move = ExecutingMove::new(
|
|
|
|
vec![],
|
|
|
|
1,
|
2022-10-14 14:53:30 +00:00
|
|
|
p1,
|
2022-09-16 09:01:37 +00:00
|
|
|
mv.clone(),
|
|
|
|
mv.move_data().clone(),
|
|
|
|
ScriptContainer::default(),
|
|
|
|
);
|
|
|
|
let mut v = 20_u8;
|
|
|
|
script.change_base_power(&executing_move, &p2, 0, &mut v);
|
|
|
|
assert_eq!(v, 20_u8);
|
|
|
|
|
|
|
|
let s = battle.sides()[1].get_volatile_script(&"assurance_data".into());
|
|
|
|
let data_script = s.as_ref().unwrap().get_as::<WebAssemblyScript>();
|
|
|
|
|
|
|
|
data_script.on_damage(&p2, DamageSource::Misc, 100, 50);
|
|
|
|
|
|
|
|
let mut v = 20_u8;
|
|
|
|
script.change_base_power(&executing_move, &p2, 0, &mut v);
|
|
|
|
assert_eq!(v, 40_u8);
|
|
|
|
|
|
|
|
data_script.on_end_turn();
|
|
|
|
assert!(!battle.sides()[1].has_volatile_script(&"assurance_data".into()));
|
|
|
|
}
|