use crate::adversarial::mutations::catalog::BinOpKind;
fn op_symbol(op: BinOpKind) -> &'static str {
match op {
BinOpKind::Lt => "<",
BinOpKind::Le => "<=",
BinOpKind::Gt => ">",
BinOpKind::Ge => ">=",
BinOpKind::Eq => "==",
BinOpKind::Ne => "!=",
BinOpKind::Add => "+",
BinOpKind::Sub => "-",
BinOpKind::Mul => "*",
BinOpKind::Div => "/",
BinOpKind::Shl => "<<",
BinOpKind::Shr => ">>",
BinOpKind::And => "&",
BinOpKind::Or => "|",
BinOpKind::Xor => "^",
}
}
#[inline]
pub fn apply_op_swap(source: &str, from: BinOpKind, to: BinOpKind) -> String {
crate::adversarial::mutations::catalog::replace_operator(
source,
op_symbol(from),
op_symbol(to),
1,
)
}
#[inline]
pub fn apply_invert(source: &str) -> String {
let tmp = crate::adversarial::mutations::catalog::lexical::replace_code_word(
source,
"true",
"__VYRE_TMP_TRUE__",
usize::MAX,
);
let tmp = crate::adversarial::mutations::catalog::lexical::replace_code_word(
&tmp,
"false",
"true",
usize::MAX,
);
let tmp = crate::adversarial::mutations::catalog::lexical::replace_code_word(
&tmp,
"__VYRE_TMP_TRUE__",
"false",
usize::MAX,
);
crate::adversarial::mutations::catalog::replace_operator(&tmp, "==", "!=", 1)
}