Add conditional loop mutator
* Closes #143 * Renamed Mutator::Node::While to ConditionalLoop and use it to generated mutations for until also.
This commit is contained in:
parent
ae4f9be3d9
commit
43c546fe74
5 changed files with 47 additions and 28 deletions
|
@ -76,7 +76,7 @@ require 'mutant/mutator/node/named_value/variable_assignment'
|
||||||
require 'mutant/mutator/node/loop_control'
|
require 'mutant/mutator/node/loop_control'
|
||||||
require 'mutant/mutator/node/noop'
|
require 'mutant/mutator/node/noop'
|
||||||
require 'mutant/mutator/node/op_asgn'
|
require 'mutant/mutator/node/op_asgn'
|
||||||
require 'mutant/mutator/node/while'
|
require 'mutant/mutator/node/conditional_loop'
|
||||||
require 'mutant/mutator/node/yield'
|
require 'mutant/mutator/node/yield'
|
||||||
require 'mutant/mutator/node/super'
|
require 'mutant/mutator/node/super'
|
||||||
require 'mutant/mutator/node/zsuper'
|
require 'mutant/mutator/node/zsuper'
|
||||||
|
|
|
@ -5,9 +5,9 @@ module Mutant
|
||||||
class Node
|
class Node
|
||||||
|
|
||||||
# Mutator for while expressions
|
# Mutator for while expressions
|
||||||
class While < self
|
class ConditionalLoop < self
|
||||||
|
|
||||||
handle(:while)
|
handle(:until, :while)
|
||||||
|
|
||||||
children :condition, :body
|
children :condition, :body
|
||||||
|
|
|
@ -15,7 +15,8 @@ module Mutant
|
||||||
:regopt, :retry, :arg_expr,
|
:regopt, :retry, :arg_expr,
|
||||||
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty,
|
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty,
|
||||||
:alias, :for, :xstr, :back_ref, :class,
|
:alias, :for, :xstr, :back_ref, :class,
|
||||||
:sclass, :match_with_lvasgn, :match_current_line
|
:sclass, :match_with_lvasgn, :match_current_line, :while_post,
|
||||||
|
:until_post, :preexe, :postexe, :iflipflop, :eflipflop, :kwsplat
|
||||||
)
|
)
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
42
spec/unit/mutant/mutator/node/conditional_loop_spec.rb
Normal file
42
spec/unit/mutant/mutator/node/conditional_loop_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Mutant::Mutator::Node::ConditionalLoop do
|
||||||
|
|
||||||
|
context 'with while statement' do
|
||||||
|
let(:source) { 'while true; foo; bar; end' }
|
||||||
|
|
||||||
|
let(:mutations) do
|
||||||
|
mutations = []
|
||||||
|
mutations << 'while true; bar; end'
|
||||||
|
mutations << 'while true; foo; end'
|
||||||
|
mutations << 'while true; end'
|
||||||
|
mutations << 'while false; foo; bar; end'
|
||||||
|
mutations << 'while nil; foo; bar; end'
|
||||||
|
mutations << 'while true; foo; nil; end'
|
||||||
|
mutations << 'while true; nil; bar; end'
|
||||||
|
mutations << 'nil'
|
||||||
|
end
|
||||||
|
|
||||||
|
it_should_behave_like 'a mutator'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with until statement' do
|
||||||
|
let(:source) { 'until true; foo; bar; end' }
|
||||||
|
|
||||||
|
let(:mutations) do
|
||||||
|
mutations = []
|
||||||
|
mutations << 'until true; bar; end'
|
||||||
|
mutations << 'until true; foo; end'
|
||||||
|
mutations << 'until true; end'
|
||||||
|
mutations << 'until false; foo; bar; end'
|
||||||
|
mutations << 'until nil; foo; bar; end'
|
||||||
|
mutations << 'until true; foo; nil; end'
|
||||||
|
mutations << 'until true; nil; bar; end'
|
||||||
|
mutations << 'nil'
|
||||||
|
end
|
||||||
|
|
||||||
|
it_should_behave_like 'a mutator'
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,24 +0,0 @@
|
||||||
# encoding: utf-8
|
|
||||||
|
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Mutant::Mutator::Node::While do
|
|
||||||
|
|
||||||
context 'with more than one statement' do
|
|
||||||
let(:source) { 'while true; foo; bar; end' }
|
|
||||||
|
|
||||||
let(:mutations) do
|
|
||||||
mutations = []
|
|
||||||
mutations << 'while true; bar; end'
|
|
||||||
mutations << 'while true; foo; end'
|
|
||||||
mutations << 'while true; end'
|
|
||||||
mutations << 'while false; foo; bar; end'
|
|
||||||
mutations << 'while nil; foo; bar; end'
|
|
||||||
mutations << 'while true; foo; nil; end'
|
|
||||||
mutations << 'while true; nil; bar; end'
|
|
||||||
mutations << 'nil'
|
|
||||||
end
|
|
||||||
|
|
||||||
it_should_behave_like 'a mutator'
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in a new issue