2012-12-06 15:30:28 -05:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
|
|
|
class Literal
|
|
|
|
# Mutator for hash literals
|
|
|
|
class Hash < self
|
|
|
|
|
|
|
|
handle(Rubinius::AST::HashLiteral)
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Emit mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
|
|
|
emit_nil
|
|
|
|
emit_values(values)
|
|
|
|
emit_element_presence
|
2012-12-06 16:33:06 -05:00
|
|
|
emit_body
|
2012-12-06 16:30:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Emit body mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-06 16:33:06 -05:00
|
|
|
def emit_body
|
2012-12-29 10:53:52 -05:00
|
|
|
emit_attribute_mutations(:array, Mutator::Util::Array::Element)
|
2012-12-06 15:30:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Return array of values in literal
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def array
|
|
|
|
node.array
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return duplicate of array values in literal
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dup_array
|
|
|
|
array.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return values to mutate against
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def values
|
2013-01-04 16:16:03 -05:00
|
|
|
nil_node = new_nil
|
|
|
|
[[], [nil_node, nil_node] + dup_array]
|
2012-12-06 15:30:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Emit element presence mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_element_presence
|
|
|
|
0.step(array.length-1, 2) do |index|
|
|
|
|
contents = dup_array
|
|
|
|
contents.delete_at(index)
|
|
|
|
contents.delete_at(index)
|
|
|
|
emit_self(contents)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|