106 lines
3.6 KiB
Rust
Executable File
106 lines
3.6 KiB
Rust
Executable File
#![feature(custom_test_frameworks)]
|
|
#![feature(lazy_cell)]
|
|
#![allow(clippy::borrowed_box)]
|
|
#![allow(clippy::arc_with_non_send_sync)]
|
|
|
|
use std::sync::{Arc, LazyLock};
|
|
|
|
use pkmn_lib::dynamic_data::{DynamicLibrary, PassChoice, PokemonBuilder, ScriptCategory, ScriptOwnerData, TurnChoice};
|
|
|
|
use crate::common::library_loader;
|
|
|
|
pub mod common;
|
|
pub mod datatests;
|
|
|
|
static LIBRARY: LazyLock<Arc<dyn DynamicLibrary>> = LazyLock::new(|| library_loader::load_library().library);
|
|
|
|
fn get_library() -> Arc<dyn DynamicLibrary> { LIBRARY.clone() }
|
|
|
|
#[test]
|
|
fn validate_library_load() {
|
|
let start_time = chrono::Utc::now();
|
|
let result = library_loader::load_library();
|
|
let end_time = chrono::Utc::now();
|
|
println!(
|
|
"Built library in {} ms\
|
|
\n\t- Types load time: {} ms\
|
|
\n\t- Natures load time: {} ms\
|
|
\n\t- Items load time: {} ms\
|
|
\n\t- Growth Rate load time: {} ms\
|
|
\n\t- Abilities load time: {} ms\
|
|
\n\t- Moves load time: {} ms\
|
|
\n\t- Species load time: {} ms\
|
|
\n\t- Script load time: {} ms\
|
|
",
|
|
(end_time - start_time).num_milliseconds(),
|
|
result.types_load_time.num_milliseconds(),
|
|
result.natures_load_time.num_milliseconds(),
|
|
result.items_load_time.num_milliseconds(),
|
|
result.growth_rate_load_time.num_milliseconds(),
|
|
result.abilities_load_time.num_milliseconds(),
|
|
result.moves_load_time.num_milliseconds(),
|
|
result.species_load_time.num_milliseconds(),
|
|
result.wasm_load_time.num_milliseconds(),
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn rune_test() {
|
|
let result = library_loader::load_library();
|
|
let library = result.library;
|
|
let p1 = PokemonBuilder::new(library.clone(), "charizard".into(), 100)
|
|
.build()
|
|
.unwrap();
|
|
|
|
let script = library
|
|
.load_script(
|
|
ScriptOwnerData::Pokemon(p1.weak()),
|
|
ScriptCategory::Move,
|
|
&"TestMove".into(),
|
|
)
|
|
.unwrap()
|
|
.unwrap();
|
|
assert_eq!(script.name().unwrap().str(), "TestMove");
|
|
let p1 = PokemonBuilder::new(library.clone(), "charizard".into(), 100)
|
|
.build()
|
|
.unwrap();
|
|
let turn_choice = Arc::new(TurnChoice::Pass(PassChoice::new(p1)));
|
|
let mut speed = 0;
|
|
script.change_speed(&turn_choice, &mut speed).unwrap();
|
|
assert_eq!(speed, 100);
|
|
}
|
|
|
|
#[test]
|
|
fn load_non_existing_wasm_script() {
|
|
let start_time = chrono::Utc::now();
|
|
let result = library_loader::load_library();
|
|
let end_time = chrono::Utc::now();
|
|
println!(
|
|
"Built library in {} ms\
|
|
\n\t- Types load time: {} ms\
|
|
\n\t- Natures load time: {} ms\
|
|
\n\t- Items load time: {} ms\
|
|
\n\t- Growth Rate load time: {} ms\
|
|
\n\t- Abilities load time: {} ms\
|
|
\n\t- Moves load time: {} ms\
|
|
\n\t- Species load time: {} ms\
|
|
\n\t- Script load time: {} ms\
|
|
",
|
|
(end_time - start_time).num_milliseconds(),
|
|
result.types_load_time.num_milliseconds(),
|
|
result.natures_load_time.num_milliseconds(),
|
|
result.items_load_time.num_milliseconds(),
|
|
result.growth_rate_load_time.num_milliseconds(),
|
|
result.abilities_load_time.num_milliseconds(),
|
|
result.moves_load_time.num_milliseconds(),
|
|
result.species_load_time.num_milliseconds(),
|
|
result.wasm_load_time.num_milliseconds(),
|
|
);
|
|
let script = result
|
|
.library
|
|
.load_script(ScriptOwnerData::None, ScriptCategory::Move, &"_____non_existing".into())
|
|
.unwrap();
|
|
|
|
assert!(script.is_none());
|
|
}
|