2012-07-27 22:39:31 +02:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
2012-07-30 22:39:03 +02:00
|
|
|
# Mutator on AST blocks
|
2012-07-27 22:39:31 +02:00
|
|
|
class Block < Mutator
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2012-07-30 22:39:03 +02:00
|
|
|
# Append mutations to block
|
|
|
|
#
|
|
|
|
# @param [#<<] generator
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-07-27 22:39:31 +02:00
|
|
|
def mutants(generator)
|
|
|
|
mutate_elements(generator)
|
|
|
|
mutate_presence(generator)
|
|
|
|
end
|
|
|
|
|
2012-07-30 22:39:03 +02:00
|
|
|
# Return block array
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-07-27 22:39:31 +02:00
|
|
|
def array
|
|
|
|
node.array
|
|
|
|
end
|
|
|
|
|
2012-07-30 22:39:03 +02:00
|
|
|
# Return duplicated block array each call
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-07-27 22:39:31 +02:00
|
|
|
def dup_array
|
|
|
|
array.dup
|
|
|
|
end
|
|
|
|
|
2012-07-30 22:39:03 +02:00
|
|
|
# Append mutations on block member presence
|
|
|
|
#
|
|
|
|
# @param [#<<] generator
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-07-27 22:39:31 +02:00
|
|
|
def mutate_presence(generator)
|
|
|
|
array.each_index do |index|
|
|
|
|
array = dup_array
|
|
|
|
array.delete_at(index)
|
|
|
|
generator << new_self(array)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-30 22:39:03 +02:00
|
|
|
# Append mutations on block elements
|
|
|
|
#
|
|
|
|
# @param [#<<] generator
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-07-27 22:39:31 +02:00
|
|
|
def mutate_elements(generator)
|
|
|
|
array.each_with_index do |child,index|
|
|
|
|
array = dup_array
|
|
|
|
Mutator.build(child).each do |mutation|
|
|
|
|
array[index]=mutation
|
|
|
|
generator << new_self(array)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|