Add range literal support

* Full of duplication. Will be addressed when all literals are done.
This commit is contained in:
Markus Schirp 2012-07-28 00:17:00 +02:00
parent 5613beec12
commit 0b9b46d12f
4 changed files with 141 additions and 0 deletions

View file

@ -91,6 +91,8 @@ require 'mutant/mutator/float_literal'
require 'mutant/mutator/array_literal'
require 'mutant/mutator/empty_array'
require 'mutant/mutator/hash_literal'
require 'mutant/mutator/range'
require 'mutant/mutator/range_exclude'
require 'mutant/mutator/block'
require 'mutant/loader'
require 'mutant/context'

View file

@ -0,0 +1,53 @@
module Mutant
class Mutator
class Range < Mutator
private
def mutants(generator)
generator << new_nil
generator << new(Rubinius::AST::RangeExclude,node.start,node.finish)
generator << new_self(neg_infinity,node.finish)
generator << new_self(nan,node.finish)
generator << new_self(node.start,infinity)
generator << new_self(node.start,nan)
end
# Return AST representing infinity
#
# @return [Rubinius::Node::AST]
#
# @api private
#
def neg_infinity
'-1.0/0.0'.to_ast.tap do |call|
call.line = node.line
end
end
# Return AST representing infinity
#
# @return [Rubinius::Node::AST]
#
# @api private
#
def infinity
'1.0/0.0'.to_ast.tap do |call|
call.line = node.line
end
end
# Return AST representing NaN
#
# @return [Rubinius::Node::AST]
#
# @api private
#
def nan
'0.0/0.0'.to_ast.tap do |call|
call.line = node.line
end
end
end
end
end

View file

@ -0,0 +1,54 @@
module Mutant
class Mutator
class RangeExclude < Mutator
private
def mutants(generator)
generator << new_nil
generator << new(Rubinius::AST::Range,node.start,node.finish)
generator << new_self(neg_infinity,node.finish)
generator << new_self(nan,node.finish)
generator << new_self(node.start,infinity)
generator << new_self(node.start,nan)
end
# Return AST representing infinity
#
# @return [Rubinius::Node::AST]
#
# @api private
#
def neg_infinity
'-1.0/0.0'.to_ast.tap do |call|
call.line = node.line
end
end
# Return AST representing infinity
#
# @return [Rubinius::Node::AST]
#
# @api private
#
def infinity
'1.0/0.0'.to_ast.tap do |call|
call.line = node.line
end
end
# Return AST representing NaN
#
# @return [Rubinius::Node::AST]
#
# @api private
#
def nan
'0.0/0.0'.to_ast.tap do |call|
call.line = node.line
end
end
end
end
end

View file

@ -203,6 +203,38 @@ describe Mutant::Mutator, '#each' do
it_should_behave_like 'a mutation enumerator method'
end
context 'range literal' do
let(:source) { '1..100' }
let(:mutations) do
mutations = []
mutations << 'nil'
mutations << '1...100'
mutations << '(0.0/0.0)..100'
mutations << '(-1.0/0.0)..100'
mutations << '1..(1.0/0.0)'
mutations << '1..(0.0/0.0)'
end
it_should_behave_like 'a mutation enumerator method'
end
context 'exclusive range literal' do
let(:source) { '1...100' }
let(:mutations) do
mutations = []
mutations << 'nil'
mutations << '1..100'
mutations << '(0.0/0.0)...100'
mutations << '(-1.0/0.0)...100'
mutations << '1...(1.0/0.0)'
mutations << '1...(0.0/0.0)'
end
it_should_behave_like 'a mutation enumerator method'
end
context 'block literal' do
let(:source) { "true\nfalse" }