Remove some duplication by using emit_body_mutations(attribute_name)
This commit is contained in:
parent
e164d1f4a9
commit
c5529ba676
5 changed files with 9 additions and 91 deletions
|
@ -1,3 +1,3 @@
|
||||||
---
|
---
|
||||||
threshold: 18
|
threshold: 18
|
||||||
total_score: 771
|
total_score: 728
|
||||||
|
|
|
@ -15,21 +15,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def dispatch
|
def dispatch
|
||||||
emit_argument_mutations
|
emit_body_mutations(:array)
|
||||||
end
|
|
||||||
|
|
||||||
# Emit argument mutations
|
|
||||||
#
|
|
||||||
# @return [undefined]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def emit_argument_mutations
|
|
||||||
Mutator::Util::Array.each(node.array) do |mutation|
|
|
||||||
dup = dup_input
|
|
||||||
dup.array = mutation
|
|
||||||
emit(dup)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,9 +15,9 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def dispatch
|
def dispatch
|
||||||
emit_condition_mutants
|
emit_body_mutations(:condition)
|
||||||
emit_if_branch_mutants
|
emit_body_mutations(:body)
|
||||||
emit_else_branch_mutants
|
emit_body_mutations(:else) if node.else
|
||||||
emit_inverted_condition
|
emit_inverted_condition
|
||||||
emit_deleted_if_branch
|
emit_deleted_if_branch
|
||||||
emit_deleted_else_branch
|
emit_deleted_else_branch
|
||||||
|
@ -33,7 +33,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def emit_inverted_condition
|
def emit_inverted_condition
|
||||||
emit_self(invert(condition), if_branch, else_branch)
|
emit_self(new_send(condition, :'!'), if_branch, else_branch)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Emit deleted else branch
|
# Emit deleted else branch
|
||||||
|
@ -58,63 +58,6 @@ module Mutant
|
||||||
emit_self(condition, else_branch, nil)
|
emit_self(condition, else_branch, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return ast that returns inverted boolean value
|
|
||||||
#
|
|
||||||
# @param [Rubinius::Node::AST] node
|
|
||||||
#
|
|
||||||
# @return [Rubinius::Node::AST]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
# Using :'!' instead of :! since syntax highlighting in vim does not
|
|
||||||
# capture literal symbol.
|
|
||||||
#
|
|
||||||
def invert(node)
|
|
||||||
if Helper.on_18?
|
|
||||||
return new(Rubinius::AST::Not, node)
|
|
||||||
end
|
|
||||||
|
|
||||||
new_send(node,:'!')
|
|
||||||
end
|
|
||||||
|
|
||||||
# Emit mutants of condition
|
|
||||||
#
|
|
||||||
# @return [undefined]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def emit_condition_mutants
|
|
||||||
Mutator.each(condition) do |mutant|
|
|
||||||
emit_self(mutant, if_branch, else_branch)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Emit if body mutations
|
|
||||||
#
|
|
||||||
# @return [undefined]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def emit_if_branch_mutants
|
|
||||||
Mutator.each(if_branch) do |mutant|
|
|
||||||
emit_self(condition, mutant, else_branch)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Emit else body mutations
|
|
||||||
#
|
|
||||||
# @return [undefined]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def emit_else_branch_mutants
|
|
||||||
body = else_branch
|
|
||||||
return unless body
|
|
||||||
Mutator.each(body) do |mutant|
|
|
||||||
emit_self(condition, if_branch, mutant)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return if_branch of node
|
# Return if_branch of node
|
||||||
#
|
#
|
||||||
# @return [Rubinius::AST::Node]
|
# @return [Rubinius::AST::Node]
|
||||||
|
|
|
@ -34,24 +34,12 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def dispatch
|
def dispatch
|
||||||
emit_receiver_mutations
|
emit_body_mutations(:receiver)
|
||||||
emit_when_branch_presence_mutations
|
emit_when_branch_presence_mutations
|
||||||
emit_else_branch_presence_mutation
|
emit_else_branch_presence_mutation
|
||||||
emit_when_branch_mutations
|
emit_when_branch_mutations
|
||||||
end
|
end
|
||||||
|
|
||||||
# Emit receiver mutation
|
|
||||||
#
|
|
||||||
# @return [undefined]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def emit_receiver_mutations
|
|
||||||
Mutator.each(receiver) do |mutant|
|
|
||||||
emit_self(mutant, when_branches, else_branch)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Emit else branch presence mutation
|
# Emit else branch presence mutation
|
||||||
#
|
#
|
||||||
# @return [undefined]
|
# @return [undefined]
|
||||||
|
@ -114,7 +102,6 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def dup_when_branches
|
def dup_when_branches
|
||||||
|
|
||||||
when_branches.dup
|
when_branches.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ module Mutant
|
||||||
# Mutators that mutates an array of inputs
|
# Mutators that mutates an array of inputs
|
||||||
class Array < self
|
class Array < self
|
||||||
|
|
||||||
|
handle(::Array)
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Emit mutations
|
# Emit mutations
|
||||||
|
|
Loading…
Add table
Reference in a new issue