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
|
# @api private
|
||||||
#
|
#
|
||||||
def mutate_if_branch
|
def mutate_if_branch
|
||||||
mutate_child(IF_BRANCH_INDEX) if if_branch
|
emit_self(condition, else_branch, nil) if else_branch
|
||||||
emit_self(condition, else_branch, nil)
|
if if_branch
|
||||||
emit_self(condition, if_branch, nil)
|
emit_self(condition, if_branch, nil)
|
||||||
|
mutate_child(IF_BRANCH_INDEX)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Emit else branch mutations
|
# Emit else branch mutations
|
||||||
|
@ -56,8 +58,10 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def mutate_else_branch
|
def mutate_else_branch
|
||||||
mutate_child(ELSE_BRANCH_INDEX)
|
if else_branch
|
||||||
emit_self(condition, s(:nil), else_branch)
|
mutate_child(ELSE_BRANCH_INDEX)
|
||||||
|
emit_self(condition, nil, else_branch)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return condition node
|
# Return condition node
|
||||||
|
|
|
@ -22,7 +22,7 @@ describe Mutant::Mutator, 'if' do
|
||||||
# Deleted else branch
|
# Deleted else branch
|
||||||
mutants << 'if :condition; true end'
|
mutants << 'if :condition; true end'
|
||||||
|
|
||||||
# Deleted if branch resuting in unless
|
# Deleted if branch resuting in unless rendering
|
||||||
mutants << 'unless :condition; false; end'
|
mutants << 'unless :condition; false; end'
|
||||||
|
|
||||||
# Deleted if branch with promoting else branch to if branch
|
# 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'
|
it_should_behave_like 'a mutator'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'unless with one branch' do
|
context 'if with one branch' do
|
||||||
let(:source) { 'unless :condition; true; end' }
|
let(:source) { 'if condition; true; end' }
|
||||||
|
|
||||||
let(:mutations) do
|
let(:mutations) do
|
||||||
mutants = []
|
mutants = []
|
||||||
mutants << 'unless !:condition; true; end'
|
mutants << 'if !condition; true; end'
|
||||||
mutants << 'unless :srandom; true; end'
|
mutants << 'if condition; false; end'
|
||||||
mutants << 'unless nil; true; end'
|
mutants << 'if condition; nil; end'
|
||||||
mutants << 'if :condition; true; end'
|
mutants << 'if true; true; end'
|
||||||
mutants << 'unless :condition; false; end'
|
mutants << 'if false; true; end'
|
||||||
mutants << 'unless :condition; nil; end'
|
|
||||||
mutants << 'unless true; true; end'
|
|
||||||
mutants << 'unless false; true; end'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_should_behave_like 'a mutator'
|
it_should_behave_like 'a mutator'
|
||||||
end
|
end
|
||||||
|
|
||||||
#context 'if with one branch' do
|
context 'unless with one branch' do
|
||||||
# let(:source) { 'if condition; true; end' }
|
let(:source) { 'unless :condition; true; end' }
|
||||||
|
|
||||||
# let(:mutations) do
|
let(:mutations) do
|
||||||
# mutants = []
|
mutants = []
|
||||||
# mutants << 'if !condition; true; end'
|
mutants << 'unless !:condition; true; end'
|
||||||
# mutants << 'if condition; false; end'
|
mutants << 'unless :srandom; true; end'
|
||||||
# mutants << 'if condition; nil; end'
|
mutants << 'unless nil; true; end'
|
||||||
# mutants << 'if true; true; end'
|
mutants << 'unless :condition; false; end'
|
||||||
# mutants << 'if false; true; end'
|
mutants << 'unless :condition; nil; end'
|
||||||
# end
|
mutants << 'unless true; true; end'
|
||||||
|
mutants << 'unless false; true; end'
|
||||||
|
mutants << 'if :condition; true; end'
|
||||||
|
end
|
||||||
|
|
||||||
# it_should_behave_like 'a mutator'
|
it_should_behave_like 'a mutator'
|
||||||
#end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue