add unit test for GameVars::normalize_varname()

This commit is contained in:
yuni 2024-06-12 00:54:26 +02:00
parent 7ec52b3503
commit 8636b08b5f

View file

@ -555,15 +555,7 @@ impl GameVars {
// and if a scope is missing, it prefixes the fallback scope.
// Should NOT be used on non-variable values, like plain strings.
//
// Some examples, assuming fallback_scope="Clippy", SCOPE_SEPARATOR="$":
//
// "" -> "clippy$"
// "foo" -> "clippy$foo"
// "FOO" -> "clippy$foo"
// "$foo" -> "clippy$foo"
// "$$foo" -> "$$foo"
// "PizzaClippy$foo" -> "pizzaclippy$foo" (unchanged)
// "$foo$foo$foo$foo" -> "$foo$foo$foo$foo" (unchanged)
// See test_normalize_varname() for examples.
pub fn normalize_varname(fallback_scope: &str, key: &str) -> String {
let parts: Vec<&str> = key.split(SCOPE_SEPARATOR).collect();
let key: String = if parts.len() == 1 {
@ -695,6 +687,17 @@ impl GameVars {
}
}
#[test]
fn test_normalize_varname() {
assert_eq!(GameVars::normalize_varname("Clippy", ""), "clippy$");
assert_eq!(GameVars::normalize_varname("Clippy", "foo"), "clippy$foo");
assert_eq!(GameVars::normalize_varname("Clippy", "FOO"), "clippy$foo");
assert_eq!(GameVars::normalize_varname("Clippy", "$foo"), "clippy$foo");
assert_eq!(GameVars::normalize_varname("Clippy", "$$foo"), "$$foo");
assert_eq!(GameVars::normalize_varname("Clippy", "PizzaClippy$foo"), "pizzaclippy$foo");
assert_eq!(GameVars::normalize_varname("Clippy", "$foo$foo$foo$foo"), "$foo$foo$foo$foo");
}
#[derive(Resource, Default)]
pub struct CommandLineOptions {
pub window_mode_fullscreen: WindowMode,