diff --git a/lib/mutant/expression/methods.rb b/lib/mutant/expression/methods.rb index 70838732..bab58e46 100644 --- a/lib/mutant/expression/methods.rb +++ b/lib/mutant/expression/methods.rb @@ -25,6 +25,22 @@ module Mutant MATCHERS.fetch(scope_symbol).new(env, scope) end + # Return length of match + # + # @param [Expression] expression + # + # @return [Fixnum] + # + # @api private + # + def match_length(expression) + if expression.syntax.start_with?(syntax) + syntax.length + else + 0 + end + end + private # Return scope name diff --git a/spec/unit/mutant/expression/methods_spec.rb b/spec/unit/mutant/expression/methods_spec.rb index 857c8337..be43fcc1 100644 --- a/spec/unit/mutant/expression/methods_spec.rb +++ b/spec/unit/mutant/expression/methods_spec.rb @@ -16,7 +16,13 @@ RSpec.describe Mutant::Expression::Methods do it { should be(object.syntax.length) } end - context 'when other is an unequivalent expression' do + context 'when other is matched' do + let(:other) { described_class.parse('TestApp::Literal#foo') } + + it { should be(object.syntax.length) } + end + + context 'when other is an not matched expression' do let(:other) { described_class.parse('Foo*') } it { should be(0) }