Collapse namespace and scope classifier similarities into baseclass

This commit is contained in:
Markus Schirp 2013-04-21 02:36:21 +02:00
parent f3ab30ae39
commit aca87664db
6 changed files with 33 additions and 9 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 16
total_score: 586
total_score: 610

View file

@ -119,7 +119,6 @@ require 'mutant/cli'
require 'mutant/cli/classifier'
require 'mutant/cli/classifier/namespace'
require 'mutant/cli/classifier/method'
require 'mutant/cli/classifier/scope'
require 'mutant/color'
require 'mutant/differ'
require 'mutant/reporter'

View file

@ -3,7 +3,6 @@ module Mutant
# A classifier for input strings
class Classifier < Matcher
include AbstractType, Adamantium::Flat, Equalizer.new(:identification)
extend DescendantsTracker
SCOPE_NAME_PATTERN = /[A-Za-z][A-Za-z_0-9]*/.freeze
METHOD_NAME_PATTERN = /[_A-Za-z][A-Za-z0-9_]*[!?=]?/.freeze
@ -11,6 +10,19 @@ module Mutant
SINGLETON_PATTERN = %r(\A(#{SCOPE_PATTERN})\z).freeze
REGISTRY = []
# Register classifier
#
# @return [undefined]
#
# @api private
#
def self.register
REGISTRY << self
end
private_class_method :register
# Return constant
#
# @param [String] location
@ -38,7 +50,7 @@ module Mutant
# @api private
#
def self.build(input)
classifiers = descendants.map do |descendant|
classifiers = REGISTRY.map do |descendant|
descendant.run(input)
end.compact

View file

@ -3,6 +3,7 @@ module Mutant
class Classifier
# Explicit method classifier
class Method < self
register
TABLE = {
'.' => Matcher::Methods::Singleton,

View file

@ -5,8 +5,6 @@ module Mutant
# Namespace classifier
class Namespace < self
REGEXP = %r(\A(#{SCOPE_PATTERN})\*\z).freeze
private
# Return matcher
@ -16,7 +14,7 @@ module Mutant
# @api private
#
def matcher
Matcher::Namespace.new(namespace)
self.class::MATCHER.new(namespace)
end
# Return namespace
@ -28,6 +26,20 @@ module Mutant
def namespace
Classifier.constant_lookup(match[1].to_s)
end
# Recursive namespace classifier
class Recursive < self
REGEXP = %r(\A(#{SCOPE_PATTERN})\*\z).freeze
MATCHER = Matcher::Namespace
register
end
# Recursive namespace classifier
class Flat < self
REGEXP = %r(\A(#{SCOPE_PATTERN})\z).freeze
MATCHER = Matcher::Scope
register
end
end
end
end

View file

@ -77,8 +77,8 @@ describe Mutant::CLI, '.new' do
end
context 'with namespace matcher' do
let(:arguments) { %w(--rspec-unit ::TestApp*) }
let(:expected_matcher) { Mutant::CLI::Classifier::Namespace.new('::TestApp*') }
let(:arguments) { %w(--rspec-unit ::TestApp*) }
let(:expected_matcher) { Mutant::CLI::Classifier::Namespace::Recursive.new('::TestApp*') }
it_should_behave_like 'a cli parser'
end