#[must_use]
pub fn expand(types: &[String]) -> Vec<String> {
let mut extensions = Vec::new();
for t in types {
match t.as_str() {
"cpp" => {
extensions.push("cpp".to_string());
extensions.push("cc".to_string());
extensions.push("cxx".to_string());
}
"h" => {
extensions.push("h".to_string());
extensions.push("hpp".to_string());
}
"yaml" => {
extensions.push("yaml".to_string());
extensions.push("yml".to_string());
}
other => extensions.push(other.to_string()),
}
}
extensions
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
#[test]
fn test_expand_multi_extension_types() {
assert_eq!(expand(&["cpp".to_string()]), vec!["cpp", "cc", "cxx"]);
assert_eq!(expand(&["h".to_string()]), vec!["h", "hpp"]);
assert_eq!(expand(&["yaml".to_string()]), vec!["yaml", "yml"]);
}
#[test]
fn test_expand_single_and_passthrough() {
assert_eq!(
expand(&["rs".to_string(), "json".to_string()]),
vec!["rs", "json"]
);
assert_eq!(expand(&["myext".to_string()]), vec!["myext"]);
assert!(expand(&[]).is_empty());
}
}