Palette unit tests.
@@ -27,6 +27,12 @@ pub fn palette_color<S: ToString>(name: &S) -> Option<RGBA> {
}
}
+/// Empties the palette
+#[allow(clippy::module_name_repetitions)]
+pub fn clear_palette() {
+ PALETTE.lock().unwrap().clear();
+}
+
macro_rules! w3c_color_helper {
( $( $n:literal, $name:expr ),* ) => {
let mut plock = PALETTE.lock().unwrap();
@@ -36,6 +42,40 @@ macro_rules! w3c_color_helper {
};
}
+#[cfg(test)]
+mod tests {
+ use crate::prelude::*;
+
+ #[test]
+ fn add_check_color() {
+ register_palette_color("red", RGB::from_f32(1.0, 0.0, 0.0));
+ let red = palette_color(&"red").unwrap();
+ assert!( red == RGBA::from_f32(1.0, 0.0, 0.0, 1.0) )
+ }
+
+ #[test]
+ fn check_w3c() {
+ add_named_colors_to_palette();
+ assert!( palette_color(&"snow").unwrap() == RGBA::named(SNOW) );
+ assert!( palette_color(&"bisque").unwrap() == RGBA::named(BISQUE) );
+ }
+
+ #[test]
+ fn clear_test() {
+ add_named_colors_to_palette();
+ clear_palette();
+ assert!( palette_color(&"snow").is_none() )
+ }
+
+ #[test]
+ fn no_such_color() {
+ add_named_colors_to_palette();
+ assert!( palette_color(&"i like fish").is_none() )
+ }
+}
+
+// --- Below here was generated with a script ---
+
/// Insert all named W3C colors into the palette
#[allow(clippy::module_name_repetitions)]
#[allow(clippy::too_many_lines)]
