From 8636b08b5f12e63000af2f4388277b2f41adc279 Mon Sep 17 00:00:00 2001 From: yuni Date: Wed, 12 Jun 2024 00:54:26 +0200 Subject: [PATCH] add unit test for GameVars::normalize_varname() --- src/var.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) 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,