Rename and tidy up the parameterized-test crate

It needed to be renamed to allow it to be published on crates.io, as there's already a parameterized_test crate there.
This commit is contained in:
Oliver Hamlet
2025-08-02 16:05:36 +01:00
parent 8cf7a0adf1
commit b75eced9ea
14 changed files with 334 additions and 167 deletions
@@ -0,0 +1,51 @@
use array_parameterized_test::{parameterized_test, test_parameter};
#[derive(Copy, Clone, Eq, PartialEq)]
enum TestValue {
A,
B,
}
#[cfg(test)]
mod tests {
use super::*;
#[test_parameter]
const INT_INPUTS: [u32; 2] = [1, 2];
#[test_parameter]
const ENUM_INPUTS: [TestValue; 2] = [TestValue::A, TestValue::B];
#[test_parameter]
const TUPLE_INPUTS: [(u32, bool); 5] =
[(1, false), (2, true), (3, false), (4, true), (5, false)];
#[expect(clippy::non_ascii_literal)]
#[test_parameter]
const NON_ASCII_INPUTS: [&str; 2] = ["nonÁscii", ""];
#[parameterized_test(INT_INPUTS)]
fn test_with_ints(value: u32) {
assert!(value > 0 && value < 3);
}
#[parameterized_test(ENUM_INPUTS)]
fn test_with_enums(value: TestValue) {
assert!(value == TestValue::A || value == TestValue::B);
}
#[parameterized_test(NON_ASCII_INPUTS)]
fn test_with_non_ascii_strings(value: &str) {
assert!(!value.is_ascii());
}
#[parameterized_test(TUPLE_INPUTS)]
fn test_with_tuples(value: (u32, bool)) {
assert_eq!(value.1, value.0.is_multiple_of(2));
}
#[parameterized_test(TUPLE_INPUTS)]
fn test_with_tuples_destructured((value, expected): (u32, bool)) {
assert_eq!(expected, value.is_multiple_of(2));
}
}
@@ -0,0 +1,85 @@
use std::path::Path;
use array_parameterized_test::{parameterized_test, test_parameter};
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[non_exhaustive]
pub enum GameType {
Oblivion,
Skyrim,
Fallout3,
FalloutNV,
Fallout4,
SkyrimSE,
Fallout4VR,
SkyrimVR,
Morrowind,
Starfield,
OpenMW,
OblivionRemastered,
}
fn has_ascii_extension(path: &Path, extension: &str) -> bool {
path.extension()
.is_some_and(|e| e.eq_ignore_ascii_case(extension))
}
fn has_plugin_file_extension(game_type: GameType, plugin_path: &Path) -> bool {
let extension = if game_type != GameType::OpenMW && has_ascii_extension(plugin_path, "ghost") {
plugin_path
.file_stem()
.and_then(|s| Path::new(s).extension())
} else {
plugin_path.extension()
};
if let Some(extension) = extension {
if extension.eq_ignore_ascii_case("esp")
|| extension.eq_ignore_ascii_case("esm")
|| (game_type == GameType::OpenMW
&& (extension.eq_ignore_ascii_case("omwaddon")
|| extension.eq_ignore_ascii_case("omwgame")
|| extension.eq_ignore_ascii_case("omwscripts")))
{
true
} else {
matches!(
game_type,
GameType::Fallout4
| GameType::Fallout4VR
| GameType::SkyrimSE
| GameType::SkyrimVR
| GameType::Starfield
) && extension.eq_ignore_ascii_case("esl")
}
} else {
false
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test_parameter]
const ALL_GAME_TYPES: [GameType; 12] = [
GameType::Oblivion,
GameType::Skyrim,
GameType::Fallout3,
GameType::FalloutNV,
GameType::Fallout4,
GameType::SkyrimSE,
GameType::Fallout4VR,
GameType::SkyrimVR,
GameType::Morrowind,
GameType::Starfield,
GameType::OpenMW,
GameType::OblivionRemastered,
];
#[parameterized_test(ALL_GAME_TYPES)]
fn should_be_true_if_file_ends_in_dot_esp_or_dot_esm(game_type: GameType) {
assert!(has_plugin_file_extension(game_type, Path::new("file.esp")));
assert!(has_plugin_file_extension(game_type, Path::new("file.esm")));
assert!(!has_plugin_file_extension(game_type, Path::new("file.bsa")));
}
}