#[inline]
pub(crate) fn is_hex_color_body(body: &str) -> bool {
matches!(body.len(), 3 | 4 | 6 | 8) && body.bytes().all(|b| b.is_ascii_hexdigit())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hex_digit_bodies_of_color_length_are_hex() {
for body in [
"abc", "ABC", "abcd", "ABCD", "aabbcc", "AABBCC", "aabbccdd", "AABBCCDD", "123ABC",
] {
assert!(is_hex_color_body(body), "#{body} is a hex color");
}
}
#[test]
fn non_hex_char_is_not_a_color() {
for body in ["ZZZ", "GGGG", "12G", "XYZABC", "ZZZZZZZZ", "12345G"] {
assert!(!is_hex_color_body(body), "#{body} is not a color");
}
}
#[test]
fn off_length_is_not_a_color() {
for body in ["", "a", "ab", "abcde", "abcdefg"] {
assert!(!is_hex_color_body(body), "#{body} is not a hex color");
}
}
}