use crate::engine::ASTRegApply;
use crate::executor::registry::converters::ResolveTargetSymbol;
use crate::executor::registry::{ConvertError, MutationConverter};
use crate::executor::spec::MutationSpec;
use ryo_analysis::AnalysisContext;
use ryo_mutations::RemoveItemMutation;
#[derive(Debug, Clone, Default)]
pub struct RemoveConverter;
impl RemoveConverter {
pub fn new() -> Self {
Self
}
}
impl ResolveTargetSymbol for RemoveConverter {}
impl MutationConverter for RemoveConverter {
fn spec_kinds(&self) -> &'static [&'static str] {
&["RemoveItem"]
}
fn convert_v2(
&self,
spec: &MutationSpec,
ctx: &AnalysisContext,
) -> Result<Vec<Box<dyn ASTRegApply>>, ConvertError> {
match spec {
MutationSpec::RemoveItem {
target: target_symbol,
item_kind,
} => {
let symbol_id = self.resolve_target_symbol(target_symbol, ctx)?;
let mutation = RemoveItemMutation::new(symbol_id, *item_kind);
Ok(vec![Box::new(mutation)])
}
_ => Err(ConvertError::TypeMismatch {
expected: "RemoveItem",
actual: spec.kind_name().to_string(),
}),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use ryo_source::ItemKind;
use ryo_symbol::SymbolId;
#[test]
fn test_remove_converter_spec_kinds() {
let converter = RemoveConverter::new();
assert_eq!(converter.spec_kinds(), &["RemoveItem"]);
}
#[test]
fn test_remove_converter_can_handle() {
let converter = RemoveConverter::new();
let spec = MutationSpec::RemoveItem {
target: crate::executor::spec::MutationTargetSymbol::ById(SymbolId::default()),
item_kind: ItemKind::Struct,
};
assert!(converter.can_handle(&spec));
}
}