Fix edge cases in begin mutator
This commit is contained in:
parent
e98a55ae87
commit
7adbb632b7
2 changed files with 34 additions and 29 deletions
|
@ -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
|
||||
|
|
|
@ -1,37 +1,33 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Mutator, 'block' do
|
||||
describe Mutant::Mutator, 'begin' do
|
||||
|
||||
context 'with more than one statement' do
|
||||
let(:source) { "true\nfalse" }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
|
||||
# Mutation of each statement in block
|
||||
mutations << "true\ntrue"
|
||||
mutations << "false\nfalse"
|
||||
mutations << "nil\nfalse"
|
||||
mutations << "true\nnil"
|
||||
|
||||
# Remove statement in block
|
||||
mutations << s(:begin, s(:true))
|
||||
mutations << s(:begin, s(:false))
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
# 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 one statement' do
|
||||
let(:source) { 'true' }
|
||||
let(:source) { "true\nfalse" }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << s(:false)
|
||||
mutations << s(:nil)
|
||||
end
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
# Mutation of each statement in block
|
||||
mutations << "true\ntrue"
|
||||
mutations << "false\nfalse"
|
||||
mutations << "nil\nfalse"
|
||||
mutations << "true\nnil"
|
||||
|
||||
# Remove statement in block
|
||||
mutations << 'true'
|
||||
mutations << 'false'
|
||||
|
||||
# Replace block with empty
|
||||
mutations << ''
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue