use super::animated_icon_type::AnimatedIconType;
use crate::common::static_svg_element::StaticSvgElement;
static HEART_ELEMENTS: &[StaticSvgElement] = &[StaticSvgElement::Path {
d: "M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",
}];
static PLUS_ELEMENTS: &[StaticSvgElement] =
&[StaticSvgElement::Path { d: "M5 12h14" }, StaticSvgElement::Path { d: "M12 5v14" }];
pub fn get_animated_icon_elements(icon_type: AnimatedIconType) -> Option<&'static [StaticSvgElement]> {
match icon_type {
AnimatedIconType::Heart => Some(HEART_ELEMENTS),
AnimatedIconType::Plus => Some(PLUS_ELEMENTS),
}
}
pub fn has_animated_icon(icon_type: AnimatedIconType) -> bool {
get_animated_icon_elements(icon_type).is_some()
}
pub fn animated_icon_count() -> usize {
AnimatedIconType::all().len()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_animated_icon_registry_heart() {
let elements = get_animated_icon_elements(AnimatedIconType::Heart).unwrap();
assert_eq!(elements.len(), 1);
match &elements[0] {
StaticSvgElement::Path { d } => {
assert!(d.contains("M19 14c1.49-1.46"));
assert!(d.contains("l7 7Z"));
}
_ => panic!("Expected Path element for Heart"),
}
}
#[test]
fn test_animated_icon_registry_plus() {
let elements = get_animated_icon_elements(AnimatedIconType::Plus).unwrap();
assert_eq!(elements.len(), 2);
match &elements[0] {
StaticSvgElement::Path { d } => assert_eq!(*d, "M5 12h14"),
_ => panic!("Expected Path element for Plus[0]"),
}
match &elements[1] {
StaticSvgElement::Path { d } => assert_eq!(*d, "M12 5v14"),
_ => panic!("Expected Path element for Plus[1]"),
}
}
#[test]
fn test_animated_icon_registry_zero_allocation() {
let elements1 = get_animated_icon_elements(AnimatedIconType::Heart).unwrap();
let elements2 = get_animated_icon_elements(AnimatedIconType::Heart).unwrap();
assert_eq!(elements1.as_ptr(), elements2.as_ptr());
match &elements1[0] {
StaticSvgElement::Path { d } => {
let ptr1 = d.as_ptr();
match &elements2[0] {
StaticSvgElement::Path { d: d2 } => {
let ptr2 = d2.as_ptr();
assert_eq!(ptr1, ptr2, "Path data should be static reference");
}
_ => panic!("Expected Path"),
}
}
_ => panic!("Expected Path"),
}
}
#[test]
fn test_has_animated_icon() {
assert!(has_animated_icon(AnimatedIconType::Heart));
assert!(has_animated_icon(AnimatedIconType::Plus));
}
#[test]
fn test_animated_icon_count() {
assert_eq!(animated_icon_count(), 2);
}
#[test]
fn test_animated_registry_completeness() {
for icon_type in AnimatedIconType::all() {
let elements = get_animated_icon_elements(*icon_type);
assert!(elements.is_some(), "Missing registry entry for {:?}", icon_type);
assert!(!elements.unwrap().is_empty(), "Empty registry entry for {:?}", icon_type);
}
}
}