From cf1c9a2bed27e8f7c8efb9d3f0338b7e55dc8f48 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 11 Aug 2014 15:21:03 +0000 Subject: [PATCH] Add relational operator mutations [fix #205] --- Changelog.md | 6 +++- lib/mutant/mutator/node/send.rb | 6 +++- meta/send.rb | 64 ++++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 3c81ad98..748b8065 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,7 +4,11 @@ * Add -j, --jobs flag to control concurrency. * Fix blind spots on send with block. * Add mutation from `foo { bar }` to `bar` -* Add mutation from `reverse_merge` to `merge` +* Add mutation from `#reverse_merge` to `#merge` +* Add mutation from `#<=` to `#<`, `#==`, `#eql?`, `#equal?` +* Add mutation from `#>=` to `#>`, `#==`, `#eql?`, `#equal?` +* Add mutation from `#>` to `#==`, `#eql?`, `#equal?` +* Add mutation from `#<` to `#==`, `#eql?`, `#equal?` * Fix reporting of diff errors to include context [tjchambers] # v0.5.26 2014-07-07 diff --git a/lib/mutant/mutator/node/send.rb b/lib/mutant/mutator/node/send.rb index 3afbcc05..0e80cd96 100644 --- a/lib/mutant/mutator/node/send.rb +++ b/lib/mutant/mutator/node/send.rb @@ -23,7 +23,11 @@ module Mutant to_s: [:to_str], to_i: [:to_int], to_a: [:to_ary], - :== => [:eql?, :equal?] + :== => [:eql?, :equal?], + :>= => [:>, :==, :eql?, :equal?], + :<= => [:<, :==, :eql?, :equal?], + :> => [:==, :eql?, :equal?], + :< => [:==, :eql?, :equal?], ) private diff --git a/meta/send.rb b/meta/send.rb index fced444c..cbbb7dbb 100644 --- a/meta/send.rb +++ b/meta/send.rb @@ -1,5 +1,67 @@ # encoding: utf-8 +Mutant::Meta::Example.add do + source 'a > b' + + singleton_mutations + mutation 'a == b' + mutation 'a.eql?(b)' + mutation 'a.equal?(b)' + mutation 'nil > b' + mutation 'self > b' + mutation 'a > nil' + mutation 'a > self' + mutation 'a' + mutation 'b' +end + +Mutant::Meta::Example.add do + source 'a >= b' + + singleton_mutations + mutation 'a > b' + mutation 'a == b' + mutation 'a.eql?(b)' + mutation 'a.equal?(b)' + mutation 'nil >= b' + mutation 'self >= b' + mutation 'a >= nil' + mutation 'a >= self' + mutation 'a' + mutation 'b' +end + +Mutant::Meta::Example.add do + source 'a <= b' + + singleton_mutations + mutation 'a < b' + mutation 'a == b' + mutation 'a.eql?(b)' + mutation 'a.equal?(b)' + mutation 'nil <= b' + mutation 'self <= b' + mutation 'a <= nil' + mutation 'a <= self' + mutation 'a' + mutation 'b' +end + +Mutant::Meta::Example.add do + source 'a < b' + + singleton_mutations + mutation 'a == b' + mutation 'a.eql?(b)' + mutation 'a.equal?(b)' + mutation 'nil < b' + mutation 'self < b' + mutation 'a < nil' + mutation 'a < self' + mutation 'a' + mutation 'b' +end + Mutant::Meta::Example.add do source 'reverse_each' @@ -319,7 +381,7 @@ Mutant::Meta::Example.add do mutation 'self[*bar]' end -(Mutant::AST::Types::BINARY_METHOD_OPERATORS - [:==, :eql?]).each do |operator| +(Mutant::AST::Types::BINARY_METHOD_OPERATORS - [:<=, :>=, :<, :>, :==, :eql?]).each do |operator| Mutant::Meta::Example.add do source "true #{operator} false"