Skip to content

Commit

Permalink
added comments, and return slice of generated mutants from apply_oper…
Browse files Browse the repository at this point in the history
…ators*
  • Loading branch information
BenTheKush committed Sep 13, 2023
1 parent ca50512 commit 7982488
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ impl Mutator {
&self.mutants
}

pub fn apply_operators_to_expression(&mut self, expr: &Expression) {
/// Apply all regular mutation operators to an expression, and add those
/// mutants to self.mutants. Return the slice of new mutants
pub fn apply_operators_to_expression(&mut self, expr: &Expression) -> &[Mutant] {
let num_mutants_at_start = self.mutants.len();
if expr.loc().try_file_no().is_some() {
let mut mutants = vec![];
for op in self.mutation_operators() {
Expand All @@ -361,26 +364,35 @@ impl Mutator {
}
self.mutants.append(&mut mutants);
}
return &self.mutants[num_mutants_at_start..self.mutants.len()];
}

pub fn apply_fallback_operators_to_expression(&mut self, expr: &Expression) {
/// Apply all fallback mutation operators to an expression, and add those
/// mutants to self.mutants. Return the slice of new mutants
pub fn apply_fallback_operators_to_expression(&mut self, expr: &Expression) -> &[Mutant] {
let num_mutants_at_start = self.mutants.len();
if expr.loc().try_file_no().is_some() {
let mut mutants = vec![];
for op in self.fallback_mutation_operators() {
mutants.append(&mut op.mutate_expression_fallback(self, expr));
}
self.mutants.append(&mut mutants);
}
return &self.mutants[num_mutants_at_start..self.mutants.len()];
}

pub fn apply_operators_to_statement(&mut self, stmt: &Statement) {
/// Apply all regular mutation operators to a statement, and add those
/// mutants to self.mutants. Return the slice of new mutants
pub fn apply_operators_to_statement(&mut self, stmt: &Statement) -> &[Mutant] {
let num_mutants_at_start = self.mutants.len();
if stmt.loc().try_file_no().is_some() {
let mut mutants = vec![];
for op in self.mutation_operators() {
mutants.append(&mut op.mutate_statement(self, stmt));
}
self.mutants.append(&mut mutants);
}
return &self.mutants[num_mutants_at_start..self.mutants.len()];
}
}

Expand Down

0 comments on commit 7982488

Please sign in to comment.