Fix index assignment mutations

This commit is contained in:
Markus Schirp 2014-06-15 15:34:45 +00:00
parent 63435e8585
commit e3d4f62f95
4 changed files with 44 additions and 4 deletions

View file

@ -1,5 +1,6 @@
# v0.5.20 2014-06-xx
* Readd mutation of index assignments
* Remove a bunch of useless mutations to nil.something
* Readd mutation of index reference arguments

View file

@ -35,8 +35,7 @@ module Mutant
#
def dispatch
emit_singletons
case selector
when INDEX_ASSIGN
if selector.equal?(INDEX_ASSIGN)
run(Index::Assign)
else
non_index_dispatch

View file

@ -10,6 +10,12 @@ module Mutant
# Mutator for index assignments
class Assign < self
define_named_child(:value, -1)
INDEX_RANGE = (2..-2).freeze
private
# Perform dispatch
#
# @return [undefined]
@ -17,7 +23,34 @@ module Mutant
# @api private
#
def dispatch
emit(receiver)
emit_naked_receiver
emit_value_mutations
emit_index_read
emit(value)
mutate_indices
end
# Mutate indices
#
# @return [undefined]
#
# @api private
#
def mutate_indices
INDEX_RANGE.begin.upto(children.length + INDEX_RANGE.end).each do |index|
delete_child(index)
mutate_child(index)
end
end
# Emit index read
#
# @return [undefined]
#
# @api private
#
def emit_index_read
emit_type(receiver, :[], *children[INDEX_RANGE])
end
end # Assign

View file

@ -90,10 +90,17 @@ Mutant::Meta::Example.add do
end
Mutant::Meta::Example.add do
source 'foo[bar]=baz'
source 'foo[bar] = baz'
singleton_mutations
mutation 'foo'
mutation 'foo[bar]'
mutation 'foo[bar] = self'
mutation 'foo[bar] = nil'
mutation 'foo[nil] = baz'
mutation 'foo[self] = baz'
mutation 'foo[] = baz'
mutation 'baz'
end
Mutant::Meta::Example.add do