tsk-22: Add function to parse env variable to a vector of strings #25

Merged
phoenix merged 8 commits from tsk-22 into main 2025-10-10 19:14:15 +00:00
2 changed files with 17 additions and 1 deletions
Showing only changes of commit c06d546ae7 - Show all commits

7
src/utility.rs Normal file
View File

@@ -0,0 +1,7 @@
pub fn split_words(var: &crate::EnvVar) -> Result<Vec<String>, std::io::Error> {
if var.has_delimiter {
Ok(var.value.split(var.delimiter).map(|c| c.parse::<String>().unwrap()).collect())
} else {
Err(std::io::Error::other("Environment variable does not have a delimiter"))
}
}

View File

@@ -116,7 +116,16 @@ mod tests {
result result
); );
assert_eq!(result.has_delimiter, true, "The {} variable has an issue finding the delimiter", result.key) assert_eq!(result.has_delimiter, true, "The {} variable has an issue finding the delimiter", result.key);
match icarus_envy::utility::split_words(&result) {
Ok(allowed_origins) => {
assert_eq!(allowed_origins.len(), 2, "The amount of allowed origins does not match. {} {}", allowed_origins.len(), 2)
}
Err(err) => {
assert!(false, "Error: {:?}", err)
}
}
} }
#[test] #[test]