Add mutations for a != b

Adds mutations which transform `a != b` into `!a.eql?(b)`
and `!a.equal?(b)`

closes #270
This commit is contained in:
John Backus 2015-08-14 03:28:45 -04:00
parent 0b8f96030a
commit 4922cea2df
3 changed files with 40 additions and 1 deletions

View file

@ -3,6 +3,7 @@
* Remove invalid mutation `super(...)` to `super`
* Add mutation from `def foo(a = true); end` to `def foo(a = true); a = true; end` #419
* Add mutation from `def foo; end` to `remove_method :foo` #413
* Add mutation from `a != b` to `!a.eql?(b)` and `!a.equal?(b)` #417
# v0.8.2 2015-08-11

View file

@ -21,6 +21,30 @@ module Mutant
emit_selector_replacement
emit(right)
emit_right_mutations
emit_not_equality_mutations
end
# Emit mutations for `!=`
#
# @return [undefined]
#
# @api private
def emit_not_equality_mutations
return unless operator.equal?(:'!=')
emit_not_equality_mutation(:eql?)
emit_not_equality_mutation(:equal?)
end
# Emit negated method sends with specified operator
#
# @param new_operator [Symbol] selector to be negated
#
# @return [undefined]
#
# @api private
def emit_not_equality_mutation(new_operator)
emit(n_not(s(:send, left, new_operator, right)))
end
end # Binary

View file

@ -425,7 +425,7 @@ Mutant::Meta::Example.add do
mutation 'self[*bar]'
end
(Mutant::AST::Types::BINARY_METHOD_OPERATORS - %i[<= >= < > == eql?]).each do |operator|
(Mutant::AST::Types::BINARY_METHOD_OPERATORS - %i[<= >= < > == != eql?]).each do |operator|
Mutant::Meta::Example.add do
source "true #{operator} false"
@ -438,3 +438,17 @@ end
mutation "true #{operator} nil"
end
end
Mutant::Meta::Example.add do
source 'a != b'
singleton_mutations
mutation 'nil != b'
mutation 'self != b'
mutation 'a'
mutation 'b'
mutation 'a != nil'
mutation 'a != self'
mutation '!a.eql?(b)'
mutation '!a.equal?(b)'
end