Remove matcher support for :: prefixed constants

Why provide such an option? I hate options. Options are bad.
References #203.
This commit is contained in:
Markus Schirp 2014-06-08 18:12:16 +00:00
parent 722d4371a5
commit 586ca63e4f
7 changed files with 19 additions and 29 deletions

View file

@ -29,7 +29,6 @@ module Mutant
symbolset = ->(strings) { strings.map(&:to_sym).to_set.freeze }
SCOPE_OPERATOR = '::'.freeze
CBASE_PATTERN = /\A#{SCOPE_OPERATOR}/.freeze
# Set of nodes that cannot be on the LHS of an assignment
NOT_ASSIGNABLE = symbolset.(%w[int float str dstr class module self nil])
@ -75,7 +74,7 @@ module Mutant
# @api private
#
def self.constant_lookup(location)
location.sub(CBASE_PATTERN, EMPTY_STRING).split(SCOPE_OPERATOR).reduce(Object) do |parent, name|
location.split(SCOPE_OPERATOR).reduce(Object) do |parent, name|
parent.const_get(name, nil)
end
end

View file

@ -13,10 +13,7 @@ module Mutant
*OPERATOR_METHODS.map(&:to_s)
).freeze
SCOPE_PATTERN = /
(?:#{SCOPE_OPERATOR})?#{SCOPE_NAME_PATTERN}
(?:#{SCOPE_OPERATOR}#{SCOPE_NAME_PATTERN})*
/x.freeze
SCOPE_PATTERN = /#{SCOPE_NAME_PATTERN}(?:#{SCOPE_OPERATOR}#{SCOPE_NAME_PATTERN})*/.freeze
REGISTRY = {}

View file

@ -9,15 +9,9 @@ module Mutant
'#' => Matcher::Methods::Instance
}.freeze
regexp = /
\A
(?<scope_name>#{SCOPE_PATTERN})
(?<scope_symbol>[.#])
(?<method_name>#{METHOD_NAME_PATTERN})
\z
/x.freeze
register(regexp)
register(
/\A(?<scope_name>#{SCOPE_PATTERN})(?<scope_symbol>[.#])(?<method_name>#{METHOD_NAME_PATTERN})\z/
)
# Return method matcher
#

View file

@ -18,26 +18,26 @@ describe 'rspec integration' do
end
specify 'it allows to kill mutations' do
expect(Kernel.system("#{base_cmd} ::TestApp::Literal#string")).to be(true)
expect(Kernel.system("#{base_cmd} TestApp::Literal#string")).to be(true)
end
specify 'it allows to exclude mutations' do
cli = <<-CMD.split("\n").join(' ')
#{base_cmd}
::TestApp::Literal#string
::TestApp::Literal#uncovered_string
--ignore-subject ::TestApp::Literal#uncovered_string
TestApp::Literal#string
TestApp::Literal#uncovered_string
--ignore-subject TestApp::Literal#uncovered_string
CMD
expect(Kernel.system(cli)).to be(true)
end
specify 'fails to kill mutations when they are not covered' do
cli = "#{base_cmd} ::TestApp::Literal#uncovered_string"
cli = "#{base_cmd} TestApp::Literal#uncovered_string"
expect(Kernel.system(cli)).to be(false)
end
specify 'fails when some mutations are not covered' do
cli = "#{base_cmd} ::TestApp::Literal"
cli = "#{base_cmd} TestApp::Literal"
expect(Kernel.system(cli)).to be(false)
end
end

View file

@ -6,8 +6,8 @@ describe Mutant::Expression::Method do
let(:object) { described_class.parse(input) }
let(:cache) { Mutant::Cache.new }
let(:instance_method) { '::TestApp::Literal#string' }
let(:singleton_method) { '::TestApp::Literal.string' }
let(:instance_method) { 'TestApp::Literal#string' }
let(:singleton_method) { 'TestApp::Literal.string' }
describe '#match_length' do
let(:input) { instance_method }

View file

@ -6,7 +6,7 @@ describe Mutant::Expression::Namespace::Exact do
let(:object) { described_class.parse(input) }
let(:cache) { Mutant::Cache.new }
let(:input) { '::TestApp::Literal' }
let(:input) { 'TestApp::Literal' }
describe '#matcher' do
subject { object.matcher(cache) }

View file

@ -6,11 +6,11 @@ describe Mutant::Expression::Namespace::Recursive do
let(:object) { described_class.parse(input) }
let(:cache) { Mutant::Cache.new }
let(:input) { '::TestApp::Literal*' }
let(:input) { 'TestApp::Literal*' }
describe '#matcher' do
subject { object.matcher(cache) }
it { should eql(Mutant::Matcher::Namespace.new(cache, '::TestApp::Literal')) }
it { should eql(Mutant::Matcher::Namespace.new(cache, 'TestApp::Literal')) }
end
describe '#match_length' do
@ -23,19 +23,19 @@ describe Mutant::Expression::Namespace::Recursive do
end
context 'when other expression describes a shorter prefix' do
let(:other) { described_class.parse('::TestApp') }
let(:other) { described_class.parse('TestApp') }
it { should be(0) }
end
context 'when other expression describes adjacent namespace' do
let(:other) { described_class.parse('::TestApp::LiteralFoo') }
let(:other) { described_class.parse('TestApp::LiteralFoo') }
it { should be(0) }
end
context 'when other expression describes a longer prefix' do
let(:other) { described_class.parse('::TestApp::Literal::Deep') }
let(:other) { described_class.parse('TestApp::Literal::Deep') }
it { should be(input[0..-2].length) }
end