From 58582a3a09c07fcfd0f736bea27f4dfba0781198 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Wed, 8 Oct 2014 14:56:46 +0000 Subject: [PATCH] Fix Expression::Method#match_length --- lib/mutant/expression/methods.rb | 16 ++++++++++++++++ spec/unit/mutant/expression/methods_spec.rb | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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) }