diff --git a/src/var.rs b/src/var.rs index ea4fadd..6f822a2 100644 --- a/src/var.rs +++ b/src/var.rs @@ -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,