Merge pull request #54 from mbj/fix-case-with-one-when

Fix case with one when
This commit is contained in:
Markus Schirp 2013-06-23 06:36:57 -07:00
commit 71b5365a81
2 changed files with 303 additions and 209 deletions

View file

@ -47,6 +47,7 @@ module Mutant
mutate_child(index)
dup_children = children.dup
dup_children.delete_at(index)
return if dup_children.none? { |child| child.type == :when }
if dup_children.last.type == :when
dup_children << nil
end

View file

@ -3,224 +3,317 @@ require 'spec_helper'
describe Mutant::Mutator::Node::Case do
let(:random_string) { 'random' }
let(:source) { ':foo' }
let(:mutations) do
%w(nil) << ":s#{random_string}"
end
before do
Mutant::Random.stub(:hex_string => random_string)
end
let(:source) do
<<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
:barbaz
else
:else
end
RUBY
context 'with multiple when branches' do
let(:source) do
<<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
:barbaz
else
:else
end
RUBY
end
let(:mutations) do
mutations = []
# Presence of branches
mutations << <<-RUBY
case :condition
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
:barbaz
end
RUBY
# Mutations of condition
mutations << <<-RUBY
case nil
when :foo
:foo
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :srandom
when :foo
:foo
when :bar, :baz
:barbaz
else
:else
end
RUBY
# Mutations of branch bodies
mutations << <<-RUBY
case :condition
when :foo
nil
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:srandom
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
:srandom
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
nil
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
:barbaz
else
:srandom
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
:barbaz
else
nil
end
RUBY
# Mutations of when conditions
mutations << <<-RUBY
case :condition
when :srandom
:foo
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when nil
:foo
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :srandom, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when nil, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, nil
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :srandom
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar
:barbaz
else
:else
end
RUBY
end
it_should_behave_like 'a mutator'
end
let(:mutations) do
mutations = []
context 'with one when branch' do
let(:source) do
<<-RUBY
case :condition
when :foo
:foo
else
:else
end
RUBY
end
# Presence of branches
mutations << <<-RUBY
case :condition
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
:barbaz
end
RUBY
let(:mutations) do
mutations = []
# Mutations of condition
mutations << <<-RUBY
case nil
when :foo
:foo
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :srandom
when :foo
:foo
when :bar, :baz
:barbaz
else
:else
end
RUBY
# Presence of branches
mutations << <<-RUBY
case :condition
when :foo
:foo
end
RUBY
# Mutations of branch bodies
mutations << <<-RUBY
case :condition
when :foo
nil
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:srandom
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
:srandom
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
nil
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
:barbaz
else
:srandom
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :baz
:barbaz
else
nil
end
RUBY
# Mutations of condition
mutations << <<-RUBY
case nil
when :foo
:foo
else
:else
end
RUBY
mutations << <<-RUBY
case :srandom
when :foo
:foo
else
:else
end
RUBY
# Mutations of when conditions
mutations << <<-RUBY
case :condition
when :srandom
:foo
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when nil
:foo
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :srandom, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when nil, :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, nil
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar, :srandom
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :baz
:barbaz
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
when :bar
:barbaz
else
:else
end
RUBY
# Mutations of branch bodies
mutations << <<-RUBY
case :condition
when :foo
nil
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:srandom
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
else
:srandom
end
RUBY
mutations << <<-RUBY
case :condition
when :foo
:foo
else
nil
end
RUBY
# Mutations of when conditions
mutations << <<-RUBY
case :condition
when :srandom
:foo
else
:else
end
RUBY
mutations << <<-RUBY
case :condition
when nil
:foo
else
:else
end
RUBY
end
it_should_behave_like 'a mutator'
end
it_should_behave_like 'a mutator'
end