Skip to main content

forge/mutation/mutators/
delete_expression_mutator.rs

1use eyre::Result;
2use solar::ast::ExprKind;
3
4use super::{MutationContext, Mutator};
5
6use crate::mutation::mutant::{Mutant, MutationType};
7
8pub struct DeleteExpressionMutator;
9
10impl Mutator for DeleteExpressionMutator {
11    fn generate_mutants(&self, ctxt: &MutationContext<'_>) -> Result<Vec<Mutant>> {
12        Ok(vec![Mutant {
13            span: ctxt.span,
14            mutation: MutationType::DeleteExpression,
15            path: ctxt.path.clone(),
16            original: ctxt.original_text(),
17            source_line: ctxt.source_line(),
18            line_number: ctxt.line_number(),
19            column_number: ctxt.column_number(),
20        }])
21    }
22
23    fn is_applicable(&self, ctxt: &MutationContext<'_>) -> bool {
24        if let Some(expr) = ctxt.expr { matches!(expr.kind, ExprKind::Delete(_)) } else { false }
25    }
26}