Add method specific subject subclass
This commit is contained in:
parent
034e47e361
commit
d34d8565d2
3 changed files with 98 additions and 15 deletions
|
@ -84,6 +84,7 @@ require 'mutant/loader'
|
|||
require 'mutant/context'
|
||||
require 'mutant/context/scope'
|
||||
require 'mutant/subject'
|
||||
require 'mutant/subject/method'
|
||||
require 'mutant/matcher'
|
||||
require 'mutant/matcher/chain'
|
||||
require 'mutant/matcher/object_space'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Mutant
|
||||
# Subject of a mutation
|
||||
class Subject
|
||||
include Adamantium::Flat, Enumerable, Equalizer.new(:context, :matcher, :node)
|
||||
include AbstractType, Adamantium::Flat, Enumerable, Equalizer.new(:context, :node)
|
||||
|
||||
# Return context
|
||||
#
|
||||
|
@ -11,14 +11,6 @@ module Mutant
|
|||
#
|
||||
attr_reader :context
|
||||
|
||||
# Return matcher
|
||||
#
|
||||
# @return [Matcher]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
attr_reader :matcher
|
||||
|
||||
# Return AST node
|
||||
#
|
||||
# @return [Rubinius::AST::Node]
|
||||
|
@ -84,7 +76,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def identification
|
||||
"#{matcher.identification}:#{source_path}:#{source_line}"
|
||||
"#{context.identitfication}#{subtype}:#{source_path}:#{source_line}"
|
||||
end
|
||||
memoize :identification
|
||||
|
||||
|
@ -126,19 +118,27 @@ module Mutant
|
|||
|
||||
# Initialize subject
|
||||
#
|
||||
# @param [Matcher] matcher
|
||||
# the context of mutations
|
||||
# @param [Mutant::Context] context
|
||||
#
|
||||
# @param [Rubinius::AST::Node] node
|
||||
# the node to be mutated
|
||||
# the original node to be mutated
|
||||
#
|
||||
# @return [unkown]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def initialize(matcher, context, node)
|
||||
@matcher, @context, @node = matcher, context, node
|
||||
def initialize(context, node)
|
||||
@context, @node = context, node
|
||||
end
|
||||
|
||||
# Return subtype identifier
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
abstract_method :subtype
|
||||
private :subtype
|
||||
|
||||
end
|
||||
end
|
||||
|
|
82
lib/mutant/subject/method.rb
Normal file
82
lib/mutant/subject/method.rb
Normal file
|
@ -0,0 +1,82 @@
|
|||
module Mutant
|
||||
class Subject
|
||||
# Abstract base class for method subjects
|
||||
class Method < self
|
||||
|
||||
# Test if method is public
|
||||
#
|
||||
# @return [true]
|
||||
# if method is public
|
||||
#
|
||||
# @return [false]
|
||||
# otherwise
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
abstract_method :public?
|
||||
|
||||
# Instance method subjects
|
||||
class Instance < self
|
||||
|
||||
# Test if method is public
|
||||
#
|
||||
# @return [true]
|
||||
# if method is public
|
||||
#
|
||||
# @return [false]
|
||||
# otherwise
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def public?
|
||||
scope.public_method_defined?(method_name)
|
||||
end
|
||||
memoize :public?
|
||||
|
||||
private
|
||||
|
||||
# Return subtype identifier
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def subtype
|
||||
"#{context.name}##{node.name}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Singleton method subjects
|
||||
class Singleton < self
|
||||
|
||||
# Test if method is public
|
||||
#
|
||||
# @return [true]
|
||||
# if method is public
|
||||
#
|
||||
# @return [false]
|
||||
# otherwise
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def public?
|
||||
scope.singleton_class.public_method_defined?(method_name)
|
||||
end
|
||||
memoize :public?
|
||||
|
||||
private
|
||||
|
||||
# Return subtype identifier
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def subtype
|
||||
"#{context.name}.#{node.name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue