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
|
||||
total_score: 1175
|
||||
total_score: 1171
|
||||
|
|
|
@ -17,9 +17,7 @@ module Mutant
|
|||
def diff
|
||||
return if diffs.empty?
|
||||
|
||||
minimized_hunks.map do |hunk|
|
||||
hunk.diff(:unified) << NEWLINE
|
||||
end.join
|
||||
minimized_hunk.diff(:unified) << NEWLINE
|
||||
end
|
||||
memoize :diff
|
||||
|
||||
|
@ -74,19 +72,15 @@ module Mutant
|
|||
end
|
||||
end
|
||||
|
||||
# Minimized hunks
|
||||
# Minimized hunk
|
||||
#
|
||||
# @return [Array<Diff::LCS::Hunk>]
|
||||
def minimized_hunks
|
||||
# @return Diff::LCS::Hunk
|
||||
def minimized_hunk
|
||||
head, *tail = hunks
|
||||
|
||||
tail.each_with_object([head]) do |right, aggregate|
|
||||
left = aggregate.last
|
||||
if right.overlaps?(left)
|
||||
right.merge(left)
|
||||
aggregate.pop
|
||||
end
|
||||
aggregate << right
|
||||
tail.reduce(head) do |left, right|
|
||||
right.merge(left)
|
||||
right
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -34,6 +34,15 @@ RSpec.describe Mutant::Diff do
|
|||
|
||||
it_should_behave_like 'an idempotent method'
|
||||
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
|
||||
|
||||
describe '#diff' do
|
||||
|
|
Loading…
Reference in a new issue