free_mutant/lib/mutant/mutator/node/literal/hash.rb

65 lines
1.2 KiB
Ruby
Raw Normal View History

module Mutant
class Mutator
class Node
class Literal
# Mutator for hash literals
class Hash < self
handle(:hash)
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_singletons
2014-06-03 03:51:22 +00:00
emit_type
2013-06-15 17:16:34 +02:00
mutate_body
end
# Mutate body
#
# @return [undefined]
#
# @api private
#
def mutate_body
2013-06-12 19:23:48 +02:00
children.each_index do |index|
mutate_child(index)
dup_children = children.dup
dup_children.delete_at(index)
2014-06-03 03:51:22 +00:00
emit_type(*dup_children)
2013-06-12 19:23:48 +02:00
end
2012-12-06 22:30:57 +01:00
end
2013-06-15 17:13:01 +02:00
# Mutator for hash pairs
2013-06-12 19:23:48 +02:00
class Pair < Node
2013-06-12 19:23:48 +02:00
handle(:pair)
children :key, :value
2013-06-12 19:23:48 +02:00
private
2013-06-12 19:23:48 +02:00
# Perform dispatch
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_key_mutations
emit_value_mutations
end
2013-06-12 19:23:48 +02:00
end # Pair
end # Hash
end # Literal
end # Node
end # Mutator
end # Mutant