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:
Markus Schirp 2013-12-29 22:32:26 +01:00
parent ae4f9be3d9
commit 43c546fe74
5 changed files with 47 additions and 28 deletions

View file

@ -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'

View file

@ -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

View file

@ -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

View 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

View file

@ -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