From e190dd45538415caafa49961026362cbd0e013a1 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Wed, 12 Jun 2013 19:04:40 +0200 Subject: [PATCH] Port if node mutator to parser --- lib/mutant/mutator/node/if.rb | 14 ++++-- .../mutant/mutator/node/if/mutation_spec.rb | 46 +++++++++---------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lib/mutant/mutator/node/if.rb b/lib/mutant/mutator/node/if.rb index ab0ee5b3..0b7cba7e 100644 --- a/lib/mutant/mutator/node/if.rb +++ b/lib/mutant/mutator/node/if.rb @@ -44,9 +44,11 @@ module Mutant # @api private # def mutate_if_branch - mutate_child(IF_BRANCH_INDEX) if if_branch - emit_self(condition, else_branch, nil) - emit_self(condition, if_branch, nil) + emit_self(condition, else_branch, nil) if else_branch + if if_branch + emit_self(condition, if_branch, nil) + mutate_child(IF_BRANCH_INDEX) + end end # Emit else branch mutations @@ -56,8 +58,10 @@ module Mutant # @api private # def mutate_else_branch - mutate_child(ELSE_BRANCH_INDEX) - emit_self(condition, s(:nil), else_branch) + if else_branch + mutate_child(ELSE_BRANCH_INDEX) + emit_self(condition, nil, else_branch) + end end # Return condition node diff --git a/spec/unit/mutant/mutator/node/if/mutation_spec.rb b/spec/unit/mutant/mutator/node/if/mutation_spec.rb index 648172b5..849a2072 100644 --- a/spec/unit/mutant/mutator/node/if/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/if/mutation_spec.rb @@ -22,7 +22,7 @@ describe Mutant::Mutator, 'if' do # Deleted else branch mutants << 'if :condition; true end' - # Deleted if branch resuting in unless + # Deleted if branch resuting in unless rendering mutants << 'unless :condition; false; end' # Deleted if branch with promoting else branch to if branch @@ -40,36 +40,36 @@ describe Mutant::Mutator, 'if' do it_should_behave_like 'a mutator' end - context 'unless with one branch' do - let(:source) { 'unless :condition; true; end' } + context 'if with one branch' do + let(:source) { 'if condition; true; end' } let(:mutations) do mutants = [] - mutants << 'unless !:condition; true; end' - mutants << 'unless :srandom; true; end' - mutants << 'unless nil; true; end' - mutants << 'if :condition; true; end' - mutants << 'unless :condition; false; end' - mutants << 'unless :condition; nil; end' - mutants << 'unless true; true; end' - mutants << 'unless false; true; end' + mutants << 'if !condition; true; end' + mutants << 'if condition; false; end' + mutants << 'if condition; nil; end' + mutants << 'if true; true; end' + mutants << 'if false; true; end' end it_should_behave_like 'a mutator' end - #context 'if with one branch' do - # let(:source) { 'if condition; true; end' } + context 'unless with one branch' do + let(:source) { 'unless :condition; true; end' } - # let(:mutations) do - # mutants = [] - # mutants << 'if !condition; true; end' - # mutants << 'if condition; false; end' - # mutants << 'if condition; nil; end' - # mutants << 'if true; true; end' - # mutants << 'if false; true; end' - # end + let(:mutations) do + mutants = [] + mutants << 'unless !:condition; true; end' + mutants << 'unless :srandom; true; end' + mutants << 'unless nil; true; end' + mutants << 'unless :condition; false; end' + mutants << 'unless :condition; nil; end' + mutants << 'unless true; true; end' + mutants << 'unless false; true; end' + mutants << 'if :condition; true; end' + end - # it_should_behave_like 'a mutator' - #end + it_should_behave_like 'a mutator' + end end