test(config): add unit tests for color_from_str function

Signed-off-by: Sandro-Alessio Gierens <sandro@gierens.de>
This commit is contained in:
Sandro-Alessio Gierens 2024-09-02 21:29:44 +02:00 committed by Christina Sørensen
parent 6dae536c9e
commit ae9f5ddc95

View file

@ -615,3 +615,50 @@ impl ThemeConfig {
FromOverride::from(ui_styles_override, Some(UiStyles::default()))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_none_color_from_string() {
["", "none", "None"].iter().for_each(|case| {
assert_eq!(color_from_str(case), None);
});
}
#[test]
fn parse_default_color_from_string() {
["default", "Default"].iter().for_each(|case| {
assert_eq!(color_from_str(case), Some(Color::Default));
});
}
#[test]
fn parse_fixed_color_from_string() {
["black", "Black"].iter().for_each(|case| {
assert_eq!(color_from_str(case), Some(Color::Black));
});
}
#[test]
fn parse_long_hex_color_from_string() {
["#ff00ff", "#FF00FF"].iter().for_each(|case| {
assert_eq!(color_from_str(case), Some(Color::Rgb(255, 0, 255)));
});
}
#[test]
fn parse_short_hex_color_from_string() {
["#f0f", "#F0F"].iter().for_each(|case| {
assert_eq!(color_from_str(case), Some(Color::Rgb(255, 0, 255)));
});
}
#[test]
fn parse_color_code_from_string() {
[("10", 10), ("01", 1)].iter().for_each(|(s, c)| {
assert_eq!(color_from_str(s), Some(Color::Fixed(*c)));
});
}
}