1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::svg::{node::Node, Svg};

#[derive(Debug, Default, Hash, Eq, PartialEq)]
pub struct RemoveCommentsOptimization;

impl RemoveCommentsOptimization {
    pub fn apply(&self, svg: &mut Svg) -> anyhow::Result<()> {
        svg.0.retain(|node| !matches!(node, Node::Comment(_)));

        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn removes_comments_from_nodes_vector() {
        let mut svg = Svg(vec![
            Node::Comment("This is a comment".to_string()),
            Node::Comment("This is another comment".to_string()),
        ]);

        let optimization = RemoveCommentsOptimization;
        optimization.apply(&mut svg).unwrap();

        assert_eq!(svg.0.len(), 0);
    }
}