From c5529ba67697f7f3c6edc7c6ac7d8910f39710bc Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Thu, 6 Dec 2012 22:03:22 +0100 Subject: [PATCH] Remove some duplication by using emit_body_mutations(attribute_name) --- config/flay.yml | 2 +- lib/mutant/mutator/node/arguments.rb | 16 +----- lib/mutant/mutator/node/if_statement.rb | 65 ++---------------------- lib/mutant/mutator/node/receiver_case.rb | 15 +----- lib/mutant/mutator/util.rb | 2 + 5 files changed, 9 insertions(+), 91 deletions(-) diff --git a/config/flay.yml b/config/flay.yml index ee7153bc..4d211ac7 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 771 +total_score: 728 diff --git a/lib/mutant/mutator/node/arguments.rb b/lib/mutant/mutator/node/arguments.rb index f4982207..1660a0ac 100644 --- a/lib/mutant/mutator/node/arguments.rb +++ b/lib/mutant/mutator/node/arguments.rb @@ -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 diff --git a/lib/mutant/mutator/node/if_statement.rb b/lib/mutant/mutator/node/if_statement.rb index ef9e816a..8af6ab32 100644 --- a/lib/mutant/mutator/node/if_statement.rb +++ b/lib/mutant/mutator/node/if_statement.rb @@ -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] diff --git a/lib/mutant/mutator/node/receiver_case.rb b/lib/mutant/mutator/node/receiver_case.rb index f6d64b7b..e9be22fd 100644 --- a/lib/mutant/mutator/node/receiver_case.rb +++ b/lib/mutant/mutator/node/receiver_case.rb @@ -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 diff --git a/lib/mutant/mutator/util.rb b/lib/mutant/mutator/util.rb index 2a6e72e1..b10b8ccd 100644 --- a/lib/mutant/mutator/util.rb +++ b/lib/mutant/mutator/util.rb @@ -34,6 +34,8 @@ module Mutant # Mutators that mutates an array of inputs class Array < self + handle(::Array) + private # Emit mutations