Handle 18 vs 19-mode differencies for if-statement
This commit is contained in:
parent
1d85b78f93
commit
890f02e7fe
3 changed files with 23 additions and 1 deletions
|
@ -19,6 +19,18 @@ module Mutant
|
|||
def self.deep_clone(object)
|
||||
Marshal.load(Marshal.dump(object))
|
||||
end
|
||||
|
||||
# Check for ruby-1.8 mode
|
||||
#
|
||||
# @return [true]
|
||||
# returns true if running under 1.8 mode
|
||||
#
|
||||
# @return [false]
|
||||
# returns false otherwise
|
||||
#
|
||||
def self.on_18?
|
||||
RUBY_VERSION == '1.8.7'
|
||||
end
|
||||
end
|
||||
|
||||
require 'mutant/support/abstract'
|
||||
|
|
|
@ -69,6 +69,10 @@ module Mutant
|
|||
# capture literal symbol.
|
||||
#
|
||||
def invert(node)
|
||||
if Mutant.on_18?
|
||||
return new(Rubinius::AST::Not,node)
|
||||
end
|
||||
|
||||
new_send(node,:'!')
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,13 @@ describe Mutant::Mutator, 'if statement' do
|
|||
mutants << 'if condition; true; else false; end'
|
||||
|
||||
# Invert condition
|
||||
if Mutant.on_18?
|
||||
# Explicitly define ast as 18-mode does swap if and else on parsing when negation condition is
|
||||
# present in condition.
|
||||
mutants << [:if, [:not, [:call, [:self], :condition, [:arglist]]], [:true], [:false]]
|
||||
else
|
||||
mutants << 'if !self.condition; true; else false; end'
|
||||
end
|
||||
|
||||
# Deleted else branch
|
||||
mutants << 'if self.condition; true end'
|
Loading…
Add table
Reference in a new issue