Cleanup node body mutation
This commit is contained in:
parent
e3754434dc
commit
fe941ff74c
12 changed files with 45 additions and 60 deletions
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 18
|
||||
total_score: 728
|
||||
total_score: 750
|
||||
|
|
|
@ -103,56 +103,24 @@ module Mutant
|
|||
end
|
||||
end
|
||||
|
||||
# Emit element presence mutations
|
||||
#
|
||||
# @param [Array] elements
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def emit_element_presence(elements)
|
||||
elements.each_index do |index|
|
||||
dup_elements = elements.dup
|
||||
dup_elements.delete_at(index)
|
||||
emit_self(dup_elements)
|
||||
end
|
||||
end
|
||||
|
||||
# Emit body mutations
|
||||
#
|
||||
# @param [Symbol] name
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def emit_mutate_attributes(method)
|
||||
body = node.public_send(method)
|
||||
def emit_attribute_mutations(name)
|
||||
body = node.public_send(name)
|
||||
|
||||
Mutator.each(body) do |mutation|
|
||||
dup = dup_node
|
||||
dup.public_send(:"#{method}=", mutation)
|
||||
dup.public_send(:"#{name}=", mutation)
|
||||
emit(dup)
|
||||
end
|
||||
end
|
||||
|
||||
# Emit body mutations
|
||||
#
|
||||
# @param [Array] body
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def emit_body(body)
|
||||
body.each_with_index do |element, index|
|
||||
dup_body = body.dup
|
||||
Mutator.each(element).each do |mutation|
|
||||
dup_body[index]=mutation
|
||||
emit_self(dup_body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Emit a new AST node with NilLiteral class
|
||||
#
|
||||
# @return [Rubinius::AST::NilLiteral]
|
||||
|
|
|
@ -15,7 +15,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
emit_mutate_attributes(:array)
|
||||
emit_attribute_mutations(:array)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -16,12 +16,7 @@ module Mutant
|
|||
#
|
||||
def dispatch
|
||||
array = input.array
|
||||
emit_body(array)
|
||||
if array.length > 1
|
||||
emit_element_presence(array)
|
||||
else
|
||||
emit_self([new_nil])
|
||||
end
|
||||
emit_attribute_mutations(:array)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
emit_mutate_attributes(:body)
|
||||
emit_attribute_mutations(:body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,9 +15,9 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
emit_mutate_attributes(:condition)
|
||||
emit_mutate_attributes(:body)
|
||||
emit_mutate_attributes(:else) if node.else
|
||||
emit_attribute_mutations(:condition)
|
||||
emit_attribute_mutations(:body)
|
||||
emit_attribute_mutations(:else) if node.else
|
||||
emit_inverted_condition
|
||||
emit_deleted_if_branch
|
||||
emit_deleted_else_branch
|
||||
|
|
|
@ -16,12 +16,10 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
body = node.body
|
||||
emit_nil
|
||||
emit_attribute_mutations(:body)
|
||||
emit_self([])
|
||||
emit_self(body.dup << new_nil)
|
||||
emit_element_presence(body)
|
||||
emit_body(body)
|
||||
emit_nil
|
||||
emit_self(node.body.dup << new_nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,25 @@ module Mutant
|
|||
emit_nil
|
||||
emit_values(values)
|
||||
emit_element_presence
|
||||
emit_body(array)
|
||||
emit_array
|
||||
end
|
||||
|
||||
# Emit body mutations
|
||||
#
|
||||
# @param [Array] body
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def emit_array
|
||||
array.each_with_index do |element, index|
|
||||
dup = dup_array
|
||||
Mutator.each(element).each do |mutation|
|
||||
dup[index]=mutation
|
||||
emit_self(dup)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Return array of values in literal
|
||||
|
|
|
@ -15,7 +15,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
emit_mutate_attributes(:body)
|
||||
emit_attribute_mutations(:body)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
emit_mutate_attributes(:receiver)
|
||||
emit_attribute_mutations(:receiver)
|
||||
emit_when_branch_presence_mutations
|
||||
emit_else_branch_presence_mutation
|
||||
emit_when_branch_mutations
|
||||
|
|
|
@ -102,7 +102,7 @@ module Mutant
|
|||
#
|
||||
def dispatch
|
||||
super
|
||||
emit_mutate_attributes(:arguments)
|
||||
emit_attribute_mutations(:arguments)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,6 +15,7 @@ describe Mutant::Mutator, 'block' do
|
|||
## Remove statement in block
|
||||
mutations << [:block, 'self.foo'.to_sexp]
|
||||
mutations << [:block, 'self.bar'.to_sexp]
|
||||
mutations << [:block]
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -27,8 +28,7 @@ describe Mutant::Mutator, 'block' do
|
|||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << [:block, 'foo'.to_sexp]
|
||||
# Empty blocks result in stack verification error
|
||||
mutations << [:block, 'nil'.to_sexp]
|
||||
mutations << [:block]
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -15,6 +15,9 @@ describe Mutant::Mutator, 'define' do
|
|||
# Remove statement in block
|
||||
mutations << 'def foo; self.baz; end'
|
||||
mutations << 'def foo; self.bar; end'
|
||||
|
||||
# Remove all statements
|
||||
mutations << [:defn, :foo, [:args], [:scope, [:block]]]
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -33,6 +36,9 @@ describe Mutant::Mutator, 'define' do
|
|||
# Body presence mutations
|
||||
mutations << 'def self.foo; self.bar; end'
|
||||
mutations << 'def self.foo; self.baz; end'
|
||||
|
||||
# Remove all statements
|
||||
mutations << [:defs, [:self], :foo, [:args], [:scope, [:block]]]
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
Loading…
Add table
Reference in a new issue