Add mutation foo.baz { bar } -> foo.bar

closes #271
This commit is contained in:
John Backus 2015-08-14 01:45:02 -04:00
parent 9d0355075d
commit 5a5e21c80e
4 changed files with 33 additions and 1 deletions

View file

@ -3,6 +3,7 @@
* Add mutation from `a != b` to `!a.eql?(b)` and `!a.equal?(b)` #417
* Add mutation `A.const_get(:B)` -> `A::B` #426
* Add mutation `def foo(*args); end` into `def foo(*args); args = []; end` #423
* Add mutation from `foo.baz { bar }` to `foo.bar` #416
# v0.8.3 2015-09-01

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 1219
total_score: 1223

View file

@ -36,6 +36,22 @@ module Mutant
return unless body
emit(body)
emit_body_mutations
mutate_body_receiver
end
# Mutate method send in body scope of `send`
#
# @return [undefined]
#
# @api private
def mutate_body_receiver
return unless n_send?(body)
body_meta = AST::Meta::Send.new(body)
send_meta = AST::Meta::Send.new(send)
emit(s(:send, send_meta.receiver, body_meta.selector, *body_meta.arguments))
end
end # Block

View file

@ -69,3 +69,18 @@ Mutant::Meta::Example.add do
mutation 'foo { |(_a)| }'
mutation 'foo'
end
Mutant::Meta::Example.add do
source 'self.foo { bar(nil) }'
singleton_mutations
mutation 'self.foo'
mutation 'foo { bar(nil) }'
mutation 'self.foo { bar }'
mutation 'self.foo { nil }'
mutation 'self.foo {}'
mutation 'self.foo { self }'
mutation 'self.foo { raise }'
mutation 'bar(nil)'
mutation 'self.bar(nil)'
end