Compare commits

...
Author SHA1 Message Date
phoenix 2a8742cc4a Removing unwrap
textsender_models PR / Rustfmt (pull_request) Successful in 58s
textsender_models PR / Check (pull_request) Successful in 1m16s
textsender_models PR / Clippy (pull_request) Successful in 1m21s
Release Tagging / release (pull_request) Successful in 36s
2026-07-02 12:36:49 -04:00
phoenix 0749e6419f Adding test 2026-07-02 12:32:29 -04:00
+41 -3
View File
@@ -2,14 +2,52 @@
/// extract it into some strings /// extract it into some strings
pub fn delimitize(var: &crate::envy::EnvVar) -> Result<Vec<String>, std::io::Error> { pub fn delimitize(var: &crate::envy::EnvVar) -> Result<Vec<String>, std::io::Error> {
if var.has_delimiter { if var.has_delimiter {
Ok(var let values: Vec<String> = match var
.value .value
.split(var.delimiter) .split(var.delimiter)
.map(|c| c.parse::<String>().unwrap()) .map(|c| c.parse::<String>())
.collect()) .collect()
{
Ok(v) => v,
Err(err) => {
return Err(std::io::Error::other(err));
}
};
Ok(values)
} else { } else {
Err(std::io::Error::other( Err(std::io::Error::other(
"Environment variable does not have a delimiter", "Environment variable does not have a delimiter",
)) ))
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_delimitize() {
let envvar = crate::envy::EnvVar {
key: "OCEANS".to_string(),
value: "Atlantic|Pacific|Indian|Arctic".to_string(),
has_delimiter: true,
delimiter: '|',
};
let all_values = vec![
"Atlantic".to_string(),
"Pacific".to_string(),
"Indian".to_string(),
"Arctic".to_string(),
];
match delimitize(&envvar) {
Ok(values) => {
assert_eq!(values, all_values, "Failure in delimitizing EnvVar values");
}
Err(err) => {
assert!(false, "Error delimitizing: {err:?}");
}
}
}
}