Merge pull request #518 from mbj/fix/diff-coverage
Fix Mutant::Diff coverage
This commit is contained in:
commit
bd1c5fd404
3 changed files with 17 additions and 14 deletions
|
@ -1,3 +1,3 @@
|
||||||
---
|
---
|
||||||
threshold: 18
|
threshold: 18
|
||||||
total_score: 1175
|
total_score: 1171
|
||||||
|
|
|
@ -17,9 +17,7 @@ module Mutant
|
||||||
def diff
|
def diff
|
||||||
return if diffs.empty?
|
return if diffs.empty?
|
||||||
|
|
||||||
minimized_hunks.map do |hunk|
|
minimized_hunk.diff(:unified) << NEWLINE
|
||||||
hunk.diff(:unified) << NEWLINE
|
|
||||||
end.join
|
|
||||||
end
|
end
|
||||||
memoize :diff
|
memoize :diff
|
||||||
|
|
||||||
|
@ -74,19 +72,15 @@ module Mutant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Minimized hunks
|
# Minimized hunk
|
||||||
#
|
#
|
||||||
# @return [Array<Diff::LCS::Hunk>]
|
# @return Diff::LCS::Hunk
|
||||||
def minimized_hunks
|
def minimized_hunk
|
||||||
head, *tail = hunks
|
head, *tail = hunks
|
||||||
|
|
||||||
tail.each_with_object([head]) do |right, aggregate|
|
tail.reduce(head) do |left, right|
|
||||||
left = aggregate.last
|
right.merge(left)
|
||||||
if right.overlaps?(left)
|
right
|
||||||
right.merge(left)
|
|
||||||
aggregate.pop
|
|
||||||
end
|
|
||||||
aggregate << right
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,15 @@ RSpec.describe Mutant::Diff do
|
||||||
|
|
||||||
it_should_behave_like 'an idempotent method'
|
it_should_behave_like 'an idempotent method'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when there is no diff' do
|
||||||
|
let(:old) { '' }
|
||||||
|
let(:new) { '' }
|
||||||
|
|
||||||
|
it { should be(nil) }
|
||||||
|
|
||||||
|
it_should_behave_like 'an idempotent method'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#diff' do
|
describe '#diff' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue