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

View file

@ -18,13 +18,13 @@ module Mutant
module_function :s module_function :s
NAN = 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 = 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 = NEW_OBJECT =
s(:send, s(:const, s(:cbase), :Object), :new) s(:send, s(:const, s(:cbase), :Object), :new)
NEGATIVE_INFINITY = 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) RAISE = s(:send, nil, :raise)

View file

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

View file

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