2012-12-06 14:44:26 -05:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
# Namespace for utility mutators
|
|
|
|
class Util < self
|
|
|
|
|
|
|
|
# Run ulitity mutator
|
|
|
|
#
|
|
|
|
# @param [Object]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.each(object, &block)
|
|
|
|
return to_enum(__method__, object) unless block_given?
|
|
|
|
|
|
|
|
new(object, block)
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
# Test if mutation is new
|
|
|
|
#
|
|
|
|
# @param [Object] generated
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# if object is new
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
|
|
|
#
|
|
|
|
def new?(generated)
|
2012-12-06 15:30:28 -05:00
|
|
|
input != generated
|
2012-12-06 14:44:26 -05:00
|
|
|
end
|
|
|
|
|
2012-12-10 11:11:08 -05:00
|
|
|
# Mutators that mutates symbol inputs
|
|
|
|
class Symbol < self
|
|
|
|
|
|
|
|
handle(::Symbol)
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Emit mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
|
|
|
emit_new { :"s#{Random.hex_string}" }
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-12-06 14:44:26 -05:00
|
|
|
# Mutators that mutates an array of inputs
|
|
|
|
class Array < self
|
|
|
|
|
2012-12-06 16:03:22 -05:00
|
|
|
handle(::Array)
|
|
|
|
|
2012-12-06 14:44:26 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
# Emit mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
|
|
|
emit_element_presence
|
|
|
|
emit_element_mutations
|
|
|
|
emit([])
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit element mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_element_mutations
|
2012-12-06 15:30:28 -05:00
|
|
|
input.each_with_index do |element, index|
|
|
|
|
dup = dup_input
|
2012-12-06 14:44:26 -05:00
|
|
|
|
|
|
|
Mutator.each(element).each do |mutation|
|
|
|
|
dup[index]=mutation
|
|
|
|
emit(dup)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit element presence mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_element_presence
|
2012-12-06 15:30:28 -05:00
|
|
|
input.each_index do |index|
|
|
|
|
dup = dup_input
|
2012-12-06 14:44:26 -05:00
|
|
|
dup.delete_at(index)
|
|
|
|
emit(dup)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|