Remove some duplication by using emit_body_mutations(attribute_name)

This commit is contained in:
Markus Schirp 2012-12-06 22:03:22 +01:00
parent e164d1f4a9
commit c5529ba676
5 changed files with 9 additions and 91 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 771
total_score: 728

View file

@ -15,21 +15,7 @@ module Mutant
# @api private
#
def dispatch
emit_argument_mutations
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
emit_body_mutations(:array)
end
end

View file

@ -15,9 +15,9 @@ module Mutant
# @api private
#
def dispatch
emit_condition_mutants
emit_if_branch_mutants
emit_else_branch_mutants
emit_body_mutations(:condition)
emit_body_mutations(:body)
emit_body_mutations(:else) if node.else
emit_inverted_condition
emit_deleted_if_branch
emit_deleted_else_branch
@ -33,7 +33,7 @@ module Mutant
# @api private
#
def emit_inverted_condition
emit_self(invert(condition), if_branch, else_branch)
emit_self(new_send(condition, :'!'), if_branch, else_branch)
end
# Emit deleted else branch
@ -58,63 +58,6 @@ module Mutant
emit_self(condition, else_branch, nil)
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 [Rubinius::AST::Node]

View file

@ -34,24 +34,12 @@ module Mutant
# @api private
#
def dispatch
emit_receiver_mutations
emit_body_mutations(:receiver)
emit_when_branch_presence_mutations
emit_else_branch_presence_mutation
emit_when_branch_mutations
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
#
# @return [undefined]
@ -114,7 +102,6 @@ module Mutant
# @api private
#
def dup_when_branches
when_branches.dup
end

View file

@ -34,6 +34,8 @@ module Mutant
# Mutators that mutates an array of inputs
class Array < self
handle(::Array)
private
# Emit mutations