From d34d8565d2ca1f667485bd389277ac676bd248e7 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 13 Jan 2013 22:25:49 +0100 Subject: [PATCH] Add method specific subject subclass --- lib/mutant.rb | 1 + lib/mutant/subject.rb | 30 ++++++------- lib/mutant/subject/method.rb | 82 ++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 lib/mutant/subject/method.rb diff --git a/lib/mutant.rb b/lib/mutant.rb index b64121e7..5e9a0e24 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -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' diff --git a/lib/mutant/subject.rb b/lib/mutant/subject.rb index 95a5286b..71c5762d 100644 --- a/lib/mutant/subject.rb +++ b/lib/mutant/subject.rb @@ -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 diff --git a/lib/mutant/subject/method.rb b/lib/mutant/subject/method.rb new file mode 100644 index 00000000..f82abc46 --- /dev/null +++ b/lib/mutant/subject/method.rb @@ -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