more test cleanup
This commit is contained in:
+10
-4
@@ -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))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user