Add initial support for Rubinius::AST::{Send,SendWithArguments}
* Only supports simple mutations currently.
This commit is contained in:
parent
9c08fad7ea
commit
55c61dfc28
4 changed files with 122 additions and 9 deletions
4
TODO
4
TODO
|
@ -16,6 +16,8 @@
|
|||
* Add some kind of a "do not touch me object" that raises on all messages.
|
||||
It can be used to make sure each literal value is touched.
|
||||
* Replace nil or add "do not touch me object" to literal mutations.
|
||||
* Add remaining literals
|
||||
* Add support remaining dynamic literals
|
||||
* Mutate options on Regexp literals
|
||||
* Use inheritable alias once (virtus,veritas,mapper,session, ...) support gem is born.
|
||||
* Mutations on Rubinius::AST::Self?
|
||||
* Support the numerous Rubinius::AST::SendWithArguments mutations.
|
||||
|
|
22
lib/mutant/mutator/send.rb
Normal file
22
lib/mutant/mutator/send.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
module Mutant
|
||||
class Mutator
|
||||
# Mutator for Rubinius::AST::Send
|
||||
class Send < Mutator
|
||||
|
||||
handle(Rubinius::AST::Send)
|
||||
|
||||
private
|
||||
|
||||
# Emit mutations
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
# Mutate "self.foo" into "foo"
|
||||
emit_self(node.receiver,node.name,true,true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
lib/mutant/mutator/send_with_arguments.rb
Normal file
28
lib/mutant/mutator/send_with_arguments.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Mutant
|
||||
class Mutator
|
||||
# Mutator for Rubinius::AST::Send
|
||||
class SendWithArguments < Mutator
|
||||
|
||||
handle(Rubinius::AST::SendWithArguments)
|
||||
|
||||
private
|
||||
|
||||
# Emit mutations
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
# FIXME: # There are MANY more mutations here :P
|
||||
#
|
||||
def dispatch
|
||||
# Mutate "foo(1)" into "self.foo(1)"
|
||||
emit_self(node.receiver,node.name,arguments,true)
|
||||
end
|
||||
|
||||
def arguments
|
||||
new(Rubinius::AST::ArrayLiteral,node.arguments.array)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -284,22 +284,83 @@ describe Mutant::Mutator, '.each' do
|
|||
end
|
||||
|
||||
context 'block literal' do
|
||||
let(:source) { "true\nfalse" }
|
||||
# Two send operations
|
||||
let(:source) { "self.foo\nself.bar" }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
|
||||
# Mutation of each statement in block
|
||||
mutations << "nil\nfalse"
|
||||
mutations << "false\nfalse"
|
||||
mutations << "true\nnil"
|
||||
mutations << "true\ntrue"
|
||||
mutations << "foo\nself.bar"
|
||||
mutations << "self.foo\nbar"
|
||||
|
||||
# Remove statement in block
|
||||
mutations << [:block, [:true]]
|
||||
mutations << [:block, [:false]]
|
||||
## Remove statement in block
|
||||
mutations << [:block,'self.foo'.to_sexp]
|
||||
mutations << [:block,'self.bar'.to_sexp]
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutation enumerator method'
|
||||
end
|
||||
|
||||
|
||||
context 'self' do
|
||||
let(:source) { 'self' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutation enumerator method'
|
||||
end
|
||||
|
||||
context 'send' do
|
||||
context 'to self' do
|
||||
|
||||
context 'implict' do
|
||||
let(:source) { 'foo' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutation enumerator method'
|
||||
end
|
||||
|
||||
context 'explict' do
|
||||
let(:source) { 'self.foo' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'foo' # without explict receiver (send privately)
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutation enumerator method'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'send with arguments' do
|
||||
context 'to self' do
|
||||
context 'implict' do
|
||||
let(:source) { 'foo(1)' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutation enumerator method'
|
||||
end
|
||||
|
||||
context 'explict' do
|
||||
let(:source) { 'self.foo(1)' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'foo(1)' # without explict receiver (send privately)
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutation enumerator method'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue