2012-07-26 13:25:23 -04:00
|
|
|
# For Veritas::Immutable. will be extracted soon
|
2012-07-23 16:54:35 -04:00
|
|
|
require 'veritas'
|
|
|
|
|
2012-07-27 16:39:31 -04:00
|
|
|
require 'securerandom'
|
|
|
|
|
2012-07-23 16:54:35 -04:00
|
|
|
# Library namespace
|
|
|
|
module Mutant
|
|
|
|
# Helper method for raising not implemented exceptions
|
|
|
|
#
|
|
|
|
# @param [Object] object
|
|
|
|
# the object where method is not implemented
|
|
|
|
#
|
|
|
|
# @raise [NotImplementedError]
|
|
|
|
# raises a not implemented error with correct description
|
|
|
|
#
|
|
|
|
# @example
|
|
|
|
# class Foo
|
2012-07-26 13:25:23 -04:00
|
|
|
# def bar
|
2012-07-23 16:54:35 -04:00
|
|
|
# Mutant.not_implemented(self)
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
2012-07-26 13:25:23 -04:00
|
|
|
# Foo.new.x # raises NotImplementedError "Foo#bar is not implemented"
|
2012-07-23 16:54:35 -04:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
2012-07-23 19:41:08 -04:00
|
|
|
#
|
2012-07-23 16:54:35 -04:00
|
|
|
def self.not_implemented(object)
|
|
|
|
method = caller(1).first[/`(.*)'/,1].to_sym
|
2012-07-23 19:41:08 -04:00
|
|
|
constant_name,delimiter = not_implemented_info(object)
|
|
|
|
raise NotImplementedError,"#{constant_name}#{delimiter}#{method} is not implemented"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return name and delimiter
|
|
|
|
#
|
|
|
|
# @param [Object] object
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.not_implemented_info(object)
|
|
|
|
if object.kind_of?(Module)
|
|
|
|
[object.name,'.']
|
|
|
|
else
|
|
|
|
[object.class.name,'#']
|
|
|
|
end
|
2012-07-23 16:54:35 -04:00
|
|
|
end
|
2012-07-23 19:41:08 -04:00
|
|
|
|
|
|
|
private_class_method :not_implemented_info
|
2012-07-27 16:39:31 -04:00
|
|
|
|
|
|
|
# Return random string
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.random_hex_string
|
|
|
|
SecureRandom.hex(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return random fixnum
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.random_fixnum
|
|
|
|
Random.rand(1000)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return random float
|
|
|
|
#
|
|
|
|
# @return [Float]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.random_fixnum
|
|
|
|
Random.rand
|
|
|
|
end
|
2012-07-23 16:54:35 -04:00
|
|
|
end
|
|
|
|
|
2012-07-26 13:25:23 -04:00
|
|
|
require 'mutant/mutator'
|
2012-07-27 16:39:31 -04:00
|
|
|
require 'mutant/mutator/true_literal'
|
|
|
|
require 'mutant/mutator/false_literal'
|
|
|
|
require 'mutant/mutator/symbol_literal'
|
|
|
|
require 'mutant/mutator/string_literal'
|
|
|
|
require 'mutant/mutator/fixnum_literal'
|
|
|
|
require 'mutant/mutator/float_literal'
|
|
|
|
require 'mutant/mutator/array_literal'
|
|
|
|
require 'mutant/mutator/empty_array'
|
|
|
|
require 'mutant/mutator/hash_literal'
|
|
|
|
require 'mutant/mutator/block'
|
2012-07-26 13:25:23 -04:00
|
|
|
require 'mutant/loader'
|
|
|
|
require 'mutant/context'
|
|
|
|
require 'mutant/context/constant'
|
|
|
|
require 'mutant/mutatee'
|
2012-07-23 16:54:35 -04:00
|
|
|
require 'mutant/matcher'
|
|
|
|
require 'mutant/matcher/method'
|
|
|
|
require 'mutant/matcher/method/singleton'
|
|
|
|
require 'mutant/matcher/method/instance'
|
|
|
|
require 'mutant/matcher/method/classifier'
|