parent
b843492828
commit
a29ffe7c98
5 changed files with 34 additions and 8 deletions
|
@ -3,6 +3,8 @@
|
|||
Changes:
|
||||
|
||||
* Remove dependency to descendants tracker
|
||||
* Add mutation #== => #eql?, #equal?
|
||||
* Add mutation #eql? => #equal?
|
||||
|
||||
# v0.5.9 2014-03-28
|
||||
|
||||
|
|
|
@ -21,8 +21,10 @@ require 'morpher'
|
|||
|
||||
# Library namespace
|
||||
module Mutant
|
||||
# The empty string used within this namespace
|
||||
# The frozen empty string used within mutant
|
||||
EMPTY_STRING = ''.freeze
|
||||
# The frozen empty array used within mutant
|
||||
EMPTY_ARRAY = [].freeze
|
||||
end # Mutant
|
||||
|
||||
require 'mutant/version'
|
||||
|
|
|
@ -11,10 +11,12 @@ module Mutant
|
|||
|
||||
children :receiver, :selector
|
||||
|
||||
SELECTOR_REPLACEMENTS = {
|
||||
send: :public_send,
|
||||
gsub: :sub
|
||||
}.freeze
|
||||
SELECTOR_REPLACEMENTS = IceNine.deep_freeze(
|
||||
send: [:public_send],
|
||||
gsub: [:sub],
|
||||
eql?: [:equal?],
|
||||
:== => [:eql?, :equal?]
|
||||
)
|
||||
|
||||
INDEX_REFERENCE = :[]
|
||||
INDEX_ASSIGN = :[]=
|
||||
|
@ -118,8 +120,9 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def emit_selector_replacement
|
||||
replacement = SELECTOR_REPLACEMENTS.fetch(selector) { return }
|
||||
emit_selector(replacement)
|
||||
SELECTOR_REPLACEMENTS.fetch(selector, EMPTY_ARRAY).each do |replacement|
|
||||
emit_selector(replacement)
|
||||
end
|
||||
end
|
||||
|
||||
# Emit naked receiver mutation
|
||||
|
|
|
@ -21,6 +21,7 @@ module Mutant
|
|||
def dispatch
|
||||
emit(left)
|
||||
emit_left_mutations
|
||||
emit_selector_replacement
|
||||
emit(right) unless right.type == :splat
|
||||
emit_right_mutations
|
||||
end
|
||||
|
|
|
@ -5,6 +5,24 @@ require 'spec_helper'
|
|||
# FIXME: This spec needs to be structured better!
|
||||
describe Mutant::Mutator, 'send' do
|
||||
|
||||
context 'when using #==' do
|
||||
let(:source) { 'foo == bar' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'foo'
|
||||
mutations << 'bar'
|
||||
mutations << 'nil == bar'
|
||||
mutations << 'foo == nil'
|
||||
mutations << 'nil'
|
||||
mutations << 'foo.eql?(bar)'
|
||||
mutations << 'foo.equal?(bar)'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
||||
|
||||
context 'when using #gsub' do
|
||||
let(:source) { 'foo.gsub(a, b)' }
|
||||
|
||||
|
@ -297,7 +315,7 @@ describe Mutant::Mutator, 'send' do
|
|||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
||||
Mutant::BINARY_METHOD_OPERATORS.each do |operator|
|
||||
(Mutant::BINARY_METHOD_OPERATORS - [:==, :eql?]).each do |operator|
|
||||
context 'on literal scalar arguments' do
|
||||
let(:source) { "true #{operator} false" }
|
||||
|
||||
|
|
Loading…
Reference in a new issue