Fix invalid ast generation on index sends

This commit is contained in:
Markus Schirp 2013-06-22 17:53:12 +02:00
parent 61d5156afb
commit 1c859483b3
3 changed files with 69 additions and 2 deletions

View file

@ -9,15 +9,70 @@ module Mutant
children :receiver, :selector
INDEX_REFERENCE = :[]
INDEX_ASSIGN = :[]=
ASSIGN_SUFFIX = :'='
# Base mutator for index operations
class Index < self
# Mutator for index references
class Reference < self
# Perform dispatch
#
# @return [undefined]
#
# @api private
#
def dispatch
emit(receiver)
end
end # Reference
# Mutator for index assignments
class Assign < self
# Perform dispatch
#
# @return [undefined]
#
# @api private
#
def dispatch
emit(receiver)
end
end # Assign
end # Index
private
# Emit mutations
# Perform dispatch
#
# @return [undefined]
#
# @api private
#
def dispatch
case selector
when INDEX_REFERENCE
run(Index::Reference)
when INDEX_ASSIGN
run(Index::Assign)
else
non_index_dispatch
end
end
# Perform non index dispatch
#
# @return [undefined]
#
# @api private
#
def non_index_dispatch
if binary_operator?
run(Binary)
return

View file

@ -19,6 +19,7 @@ module Mutant
info(object.identification)
end
# Prunter for subject runners
class Runner < self
handle(Mutant::Runner::Subject)
@ -64,7 +65,6 @@ module Mutant
# @api private
#
def print_stats
p coverage
status('(%02d/%02d) %3d%% - %0.02fs', amount_kills, amount_mutations, coverage, time)
end

View file

@ -3,6 +3,18 @@ require 'spec_helper'
# FIXME: This spec needs to be structured better!
describe Mutant::Mutator, 'send' do
context 'index assign' do
let(:source) { 'foo[bar]=baz' }
let(:mutations) do
mutations = []
mutations << 'foo'
end
it_should_behave_like 'a mutator'
end
context 'with only a splat arg' do
let(:source) { 'foo(*bar)' }