diff --git a/lib/mutant.rb b/lib/mutant.rb index f451495b..9f87c464 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -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 diff --git a/lib/mutant/expression.rb b/lib/mutant/expression.rb index 28311d5e..7e9ea7ee 100644 --- a/lib/mutant/expression.rb +++ b/lib/mutant/expression.rb @@ -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 = {} diff --git a/lib/mutant/expression/method.rb b/lib/mutant/expression/method.rb index 9c86f78e..c7a6ae00 100644 --- a/lib/mutant/expression/method.rb +++ b/lib/mutant/expression/method.rb @@ -9,15 +9,9 @@ module Mutant '#' => Matcher::Methods::Instance }.freeze - regexp = / - \A - (?#{SCOPE_PATTERN}) - (?[.#]) - (?#{METHOD_NAME_PATTERN}) - \z - /x.freeze - - register(regexp) + register( + /\A(?#{SCOPE_PATTERN})(?[.#])(?#{METHOD_NAME_PATTERN})\z/ + ) # Return method matcher # diff --git a/spec/integration/mutant/rspec_spec.rb b/spec/integration/mutant/rspec_spec.rb index e16afbe5..4e6326e5 100644 --- a/spec/integration/mutant/rspec_spec.rb +++ b/spec/integration/mutant/rspec_spec.rb @@ -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 diff --git a/spec/unit/mutant/expression/method_spec.rb b/spec/unit/mutant/expression/method_spec.rb index 6640fde8..7e70ee0a 100644 --- a/spec/unit/mutant/expression/method_spec.rb +++ b/spec/unit/mutant/expression/method_spec.rb @@ -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 } diff --git a/spec/unit/mutant/expression/namespace/flat_spec.rb b/spec/unit/mutant/expression/namespace/flat_spec.rb index 87ce5e0e..177defcc 100644 --- a/spec/unit/mutant/expression/namespace/flat_spec.rb +++ b/spec/unit/mutant/expression/namespace/flat_spec.rb @@ -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) } diff --git a/spec/unit/mutant/expression/namespace/recursive_spec.rb b/spec/unit/mutant/expression/namespace/recursive_spec.rb index 1dd08908..215456d5 100644 --- a/spec/unit/mutant/expression/namespace/recursive_spec.rb +++ b/spec/unit/mutant/expression/namespace/recursive_spec.rb @@ -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