Port if node mutator to parser
This commit is contained in:
parent
c5cdc05e5e
commit
e190dd4553
2 changed files with 32 additions and 28 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue