Merge pull request #89 from mbj/named-capture-regexp
WIP - Replace position regexp matching with named captures
This commit is contained in:
commit
39f508060f
4 changed files with 60 additions and 16 deletions
|
@ -15,17 +15,12 @@ module Mutant
|
|||
|
||||
REGEXP = /
|
||||
\A
|
||||
(#{SCOPE_PATTERN})
|
||||
([.#])
|
||||
(#{METHOD_NAME_PATTERN})
|
||||
(?<scope_name>#{SCOPE_PATTERN})
|
||||
(?<scope_symbol>[.#])
|
||||
(?<method_name>#{METHOD_NAME_PATTERN})
|
||||
\z
|
||||
/x.freeze
|
||||
|
||||
# Positions of captured regexp groups
|
||||
SCOPE_NAME_POSITION = 1
|
||||
SCOPE_SYMBOL_POSITION = 2
|
||||
METHOD_NAME_POSITION = 3
|
||||
|
||||
private
|
||||
|
||||
# Return method matcher
|
||||
|
@ -59,7 +54,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def scope_name
|
||||
match[SCOPE_NAME_POSITION]
|
||||
match[__method__]
|
||||
end
|
||||
|
||||
# Return scope
|
||||
|
@ -79,7 +74,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def method_name
|
||||
match[METHOD_NAME_POSITION].to_sym
|
||||
match[__method__].to_sym
|
||||
end
|
||||
|
||||
# Return scope symbol
|
||||
|
@ -89,7 +84,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def scope_symbol
|
||||
match[SCOPE_SYMBOL_POSITION]
|
||||
match[__method__]
|
||||
end
|
||||
|
||||
# Return matcher class
|
||||
|
|
|
@ -26,12 +26,12 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def namespace
|
||||
Classifier.constant_lookup(match[1].to_s)
|
||||
Classifier.constant_lookup(match[__method__].to_s)
|
||||
end
|
||||
|
||||
# Recursive namespace classifier
|
||||
class Recursive < self
|
||||
REGEXP = /\A(#{SCOPE_PATTERN})\*\z/.freeze
|
||||
REGEXP = /\A(?<namespace>#{SCOPE_PATTERN})\*\z/.freeze
|
||||
MATCHER = Matcher::Namespace
|
||||
|
||||
register
|
||||
|
@ -39,7 +39,7 @@ module Mutant
|
|||
|
||||
# Recursive namespace classifier
|
||||
class Flat < self
|
||||
REGEXP = /\A(#{SCOPE_PATTERN})\z/.freeze
|
||||
REGEXP = /\A(?<namespace>#{SCOPE_PATTERN})\z/.freeze
|
||||
MATCHER = Matcher::Scope
|
||||
|
||||
register
|
||||
|
|
|
@ -7,7 +7,7 @@ module Mutant
|
|||
# Scope classifier
|
||||
class Scope < self
|
||||
|
||||
REGEXP = /\A(#{SCOPE_PATTERN})\z/.freeze
|
||||
REGEXP = /\A(?<scope>#{SCOPE_PATTERN})\z/.freeze
|
||||
|
||||
private
|
||||
|
||||
|
@ -28,7 +28,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def scope
|
||||
Classifier.constant_lookup(match[1].to_s)
|
||||
Classifier.constant_lookup(match[__method__].to_s)
|
||||
end
|
||||
|
||||
end # Scope
|
||||
|
|
49
lib/mutant/mutation/filter/code.rb
Normal file
49
lib/mutant/mutation/filter/code.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
# encoding: utf-8
|
||||
|
||||
module Mutant
|
||||
class Mutation
|
||||
class Filter
|
||||
# Mutation filter that filters on mutation codes
|
||||
class Code < self
|
||||
include Concord::Public.new(:code)
|
||||
|
||||
# Test for match
|
||||
#
|
||||
# @param [Mutation] mutation
|
||||
#
|
||||
# @return [true]
|
||||
# returns true if mutation code matches filter code
|
||||
#
|
||||
# @return [false]
|
||||
# returns false otherwise
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def match?(mutation)
|
||||
mutation.code.eql?(code)
|
||||
end
|
||||
|
||||
PATTERN = /\Acode:(?<code>[a-f0-9]{1,6})\z/.freeze
|
||||
|
||||
# Test if class handles string
|
||||
#
|
||||
# @param [String] notation
|
||||
#
|
||||
# @return [Filter]
|
||||
# return code filter instance if notation matches pattern
|
||||
#
|
||||
# @return [nil]
|
||||
# returns nil otherwise
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def self.handle(notation)
|
||||
match = PATTERN.match(notation)
|
||||
return unless match
|
||||
new(match[:code])
|
||||
end
|
||||
|
||||
end # Code
|
||||
end # Filter
|
||||
end # Mutation
|
||||
end # Mutant
|
Loading…
Add table
Reference in a new issue