pub fn create_svg(size: u32, background: &str, shapes: &str, blackout: &str) -> String {
format!(
r#"<svg
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="{size}"
height="{size}"
viewBox="0 0 500 500"
>
{background}
{shapes}
{blackout}
</svg>"#
)
}
pub fn create_background(round: bool, color: &str) -> String {
let rx = if round { 250 } else { 0 };
format!(
r#"<rect
width="500"
height="500"
rx="{rx}"
fill="{color}"
/>"#
)
}
pub fn create_blackout(round: bool) -> String {
let d = if round {
"M250,0a250,250 0 1,1 0,500"
} else {
"M250,0L500,0L500,500L250,500"
};
format!(
r#"<path
d="{d}"
fill="\#15212a"
fill-opacity="0.08"
/>"#
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_create_background_shape() {
let round_bg = create_background(true, "#ffffff");
assert!(round_bg.contains("rx=\"250\""));
assert!(round_bg.contains("fill=\"#ffffff\""));
let square_bg = create_background(false, "#000000");
assert!(square_bg.contains("rx=\"0\""));
assert!(square_bg.contains("fill=\"#000000\""));
}
#[test]
fn test_create_blackout_shape() {
let round_blackout = create_blackout(true);
assert!(round_blackout.contains("d=\"M250,0a250,250 0 1,1 0,500\""));
let square_blackout = create_blackout(false);
assert!(square_blackout.contains("d=\"M250,0L500,0L500,500L250,500\""));
}
#[test]
fn test_create_svg_wrapper() {
let svg = create_svg(200, "<bg/>", "<shapes/>", "<blackout/>");
assert!(svg.contains("width=\"200\""));
assert!(svg.contains("height=\"200\""));
assert!(svg.contains("<bg/>"));
assert!(svg.contains("<shapes/>"));
assert!(svg.contains("<blackout/>"));
}
}