Browse Source

test(config): add unit tests for color_from_str function

Signed-off-by: Sandro-Alessio Gierens <sandro@gierens.de>
Sandro-Alessio Gierens 1 year ago
parent
commit
ae9f5ddc95
1 changed files with 47 additions and 0 deletions
  1. 47 0
      src/options/config.rs

+ 47 - 0
src/options/config.rs

@@ -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)));
+        });
+    }
+}