Also mutate define arguments

This commit is contained in:
Markus Schirp 2012-12-10 17:26:56 +01:00
parent 585fc54915
commit 5fed2cb57f
3 changed files with 76 additions and 1 deletions

View file

@ -1,5 +1,6 @@
# v0.2.4 2012-12-08
* [feature] define block arguments
* [feature] Mutate block arguments, inklusive pattern args
* [feature] Recurse into block bodies
* [fixed] Crash on mutating yield, added a noop for now

View file

@ -4,9 +4,26 @@ module Mutant
class Define < self
handle(Rubinius::AST::Define)
handle(Rubinius::AST::DefineSingleton)
handle(Rubinius::AST::DefineSingletonScope)
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_attribute_mutations(:body)
emit_attribute_mutations(:arguments)
end
end
class DefineSingleton < self
handle(Rubinius::AST::DefineSingleton)
private
# Emit mutations

View file

@ -23,6 +23,35 @@ describe Mutant::Mutator, 'define' do
it_should_behave_like 'a mutator'
end
context 'with arguments' do
let(:source) { 'def foo(a, b); nil; end' }
before do
Mutant::Random.stub(:hex_string => 'random')
end
let(:mutations) do
mutations = []
# Deletion of each argument
mutations << 'def foo(a); nil; end'
mutations << 'def foo(b); nil; end'
# Deletion of all arguments
mutations << 'def foo; nil; end'
# Rename each argument
mutations << 'def foo(srandom, b); nil; end'
mutations << 'def foo(a, srandom); nil; end'
# Mutation of body
mutations << 'def foo(a, b); Object.new; end'
end
it_should_behave_like 'a mutator'
end
context 'define on singleton' do
let(:source) { 'def self.foo; self.bar; self.baz; end' }
@ -44,4 +73,32 @@ describe Mutant::Mutator, 'define' do
it_should_behave_like 'a mutator'
end
context 'define on singleton with argument' do
before do
Mutant::Random.stub(:hex_string => 'random')
end
let(:source) { 'def self.foo(a, b); nil; end' }
let(:mutations) do
mutations = []
# Deletion of each argument
mutations << 'def self.foo(a); nil; end'
mutations << 'def self.foo(b); nil; end'
# Deletion of all arguments
mutations << 'def self.foo; nil; end'
# Rename each argument
mutations << 'def self.foo(srandom, b); nil; end'
mutations << 'def self.foo(a, srandom); nil; end'
# Mutation of body
mutations << 'def self.foo(a, b); Object.new; end'
end
it_should_behave_like 'a mutator'
end
end