Refactor mutation emitter to support unparser 0.1.0

Cleans up the body mutator and fix blind spot.
This commit is contained in:
Markus Schirp 2013-09-06 01:43:17 +02:00
parent f2f097e5e9
commit 212831b107
4 changed files with 18 additions and 15 deletions

View file

@ -19,9 +19,7 @@ module Mutant
#
def dispatch
Util::Array.each(children, self) do |children|
if children.length > 1
emit_self(*children)
end
emit_child_subset(children)
end
children.each_with_index do |child, index|
mutate_child(index)
@ -29,18 +27,22 @@ module Mutant
end
end
# Test if parent input is a send
# Emit child subset
#
# @return [true]
# if parent input is a send node
# @param [Array<Parser::AST::Node>] nodes
#
# @return [false]
# otherwise
# @return [undefined]
#
# @api private
#
def parent_send?
parent && parent.input.type == :send
def emit_child_subset(children)
case children.length
when 0
when 1
emit(children.first)
else
emit_self(*children)
end
end
end # Block

View file

@ -18,13 +18,13 @@ module Mutant
module_function :s
NAN =
s(:begin, s(:send, s(:float, 0.0), :/, s(:args, s(:float, 0.0))))
s(:send, s(:float, 0.0), :/, s(:args, s(:float, 0.0)))
INFINITY =
s(:begin, s(:send, s(:float, 1.0), :/, s(:args, s(:float, 0.0))))
s(:send, s(:float, 1.0), :/, s(:args, s(:float, 0.0)))
NEW_OBJECT =
s(:send, s(:const, s(:cbase), :Object), :new)
NEGATIVE_INFINITY =
s(:begin, s(:send, s(:float, -1.0), :/, s(:args, s(:float, 0.0))))
s(:send, s(:float, -1.0), :/, s(:args, s(:float, 0.0)))
RAISE = s(:send, nil, :raise)

View file

@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
gem.executables = %w[mutant]
gem.add_runtime_dependency('parser', '~> 2.0.0.pre6')
gem.add_runtime_dependency('unparser', '~> 0.0.17')
gem.add_runtime_dependency('unparser', '~> 0.1.0')
gem.add_runtime_dependency('ice_nine', '~> 0.8')
gem.add_runtime_dependency('descendants_tracker', '~> 0.0.1')
gem.add_runtime_dependency('adamantium', '~> 0.1.0')

View file

@ -86,8 +86,9 @@ shared_examples_for 'a mutator' do
if message.any?
message = sprintf(
"Original:\n%s\n-----\n%s",
"Original:\n%s\n%s\n-----\n%s",
generate(node),
node.inspect,
message.join("\n-----\n")
)