2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-29 22:53:50 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Diff::InlineDiff do
|
2021-04-29 21:17:54 +05:30
|
|
|
describe '#inline_diffs' do
|
|
|
|
subject { described_class.new(old_line, new_line, offset: offset).inline_diffs }
|
2016-01-29 22:53:50 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
let(:old_line) { 'XXX def initialize(test = true)' }
|
|
|
|
let(:new_line) { 'YYY def initialize(test = false)' }
|
|
|
|
let(:offset) { 3 }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it 'finds the inline diff', :aggregate_failures do
|
|
|
|
expect(subject[0]).to eq([Gitlab::MarkerRange.new(26, 28, mode: :deletion)])
|
|
|
|
expect(subject[1]).to eq([Gitlab::MarkerRange.new(26, 29, mode: :addition)])
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
context 'when lines have multiple changes' do
|
2021-04-29 21:17:54 +05:30
|
|
|
let(:old_line) { '- Hello, how are you?' }
|
|
|
|
let(:new_line) { '+ Hi, how are you doing?' }
|
|
|
|
let(:offset) { 1 }
|
|
|
|
|
|
|
|
it 'finds all inline diffs', :aggregate_failures do
|
|
|
|
expect(subject[0]).to eq([Gitlab::MarkerRange.new(3, 6, mode: :deletion)])
|
|
|
|
expect(subject[1]).to eq([
|
|
|
|
Gitlab::MarkerRange.new(3, 3, mode: :addition),
|
|
|
|
Gitlab::MarkerRange.new(17, 22, mode: :addition)
|
|
|
|
])
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
end
|
2016-01-29 22:53:50 +05:30
|
|
|
end
|
|
|
|
end
|