Fix edge cases in begin mutator

This commit is contained in:
Markus Schirp 2013-06-21 15:05:27 +02:00
parent e98a55ae87
commit 7adbb632b7
2 changed files with 34 additions and 29 deletions

View file

@ -1,6 +1,7 @@
module Mutant
class Mutator
class Node
# Mutator for begin nodes
class Begin < self
@ -15,7 +16,15 @@ module Mutant
# @api private
#
def dispatch
emit_children_mutations
Util::Array.each(children) do |children|
if children.length > 1
emit_self(*children)
end
end
children.each do |child|
emit(child)
end
emit(nil)
end
end # Block

View file

@ -1,8 +1,15 @@
require 'spec_helper'
describe Mutant::Mutator, 'block' do
describe Mutant::Mutator, 'begin' do
# This mutation and only this mutation can result in
# and empty emit that is parsed into nil, unparser cannot
# handle this so we guard this here!
def generate(node)
return '' if node.nil?
super
end
context 'with more than one statement' do
let(:source) { "true\nfalse" }
let(:mutations) do
@ -15,23 +22,12 @@ describe Mutant::Mutator, 'block' do
mutations << "true\nnil"
# Remove statement in block
mutations << s(:begin, s(:true))
mutations << s(:begin, s(:false))
mutations << 'nil'
mutations << 'true'
mutations << 'false'
# Replace block with empty
mutations << ''
end
it_should_behave_like 'a mutator'
end
context 'with one statement' do
let(:source) { 'true' }
let(:mutations) do
mutations = []
mutations << s(:false)
mutations << s(:nil)
end
it_should_behave_like 'a mutator'
end
end