Fix invalid ast generation on index sends
This commit is contained in:
parent
61d5156afb
commit
1c859483b3
3 changed files with 69 additions and 2 deletions
|
@ -9,15 +9,70 @@ module Mutant
|
||||||
|
|
||||||
children :receiver, :selector
|
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
|
private
|
||||||
|
|
||||||
# Emit mutations
|
# Perform dispatch
|
||||||
#
|
#
|
||||||
# @return [undefined]
|
# @return [undefined]
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def dispatch
|
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?
|
if binary_operator?
|
||||||
run(Binary)
|
run(Binary)
|
||||||
return
|
return
|
||||||
|
|
|
@ -19,6 +19,7 @@ module Mutant
|
||||||
info(object.identification)
|
info(object.identification)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Prunter for subject runners
|
||||||
class Runner < self
|
class Runner < self
|
||||||
|
|
||||||
handle(Mutant::Runner::Subject)
|
handle(Mutant::Runner::Subject)
|
||||||
|
@ -64,7 +65,6 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def print_stats
|
def print_stats
|
||||||
p coverage
|
|
||||||
status('(%02d/%02d) %3d%% - %0.02fs', amount_kills, amount_mutations, coverage, time)
|
status('(%02d/%02d) %3d%% - %0.02fs', amount_kills, amount_mutations, coverage, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,18 @@ require 'spec_helper'
|
||||||
# FIXME: This spec needs to be structured better!
|
# FIXME: This spec needs to be structured better!
|
||||||
describe Mutant::Mutator, 'send' do
|
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
|
context 'with only a splat arg' do
|
||||||
let(:source) { 'foo(*bar)' }
|
let(:source) { 'foo(*bar)' }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue