more test cleanup

This commit is contained in:
2026-07-25 23:20:52 -05:00
parent c3be2329c0
commit ba8c72d5a5
12 changed files with 117 additions and 164 deletions
+10 -4
View File
@@ -135,11 +135,17 @@ impl ScriptKey {
}
}
pub fn source<'a>(&self, sources: &'a HashMap<String, String>) -> Option<&'a str> {
/// Attempt to find and return the source for the given script key:
/// - For `None`, return Ok(None) since there's not a script to find
/// - For `World`, return either Ok(Some(&str)) or Err if it's not in the given hashmap
/// - For `Builtin`, return Ok(Some(&str)) assuming the builtin is a valid name (Err in the unlikely case...)
pub fn source<'a>(&self, sources: &'a HashMap<String, String>) -> Result<Option<&'a str>, String> {
match self {
ScriptKey::None => None,
ScriptKey::World(name) => sources.get(name).map(String::as_str),
key @ ScriptKey::Builtin(_) => BUILTIN_SOURCES.get(key).copied(),
ScriptKey::None => Ok(None),
ScriptKey::World(name) => sources.get(name).map(String::as_str)
.map_or(Err(format!("unknown script '{name}'")), |s| Ok(Some(s))),
key @ ScriptKey::Builtin(name) => BUILTIN_SOURCES.get(key)
.map_or(Err(format!("No builtin script '{name}'")), |s| Ok(Some(*s))),
}
}
}