2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-29 22:53:50 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Gitlab::Diff::InlineDiff do
|
2016-04-02 18:10:28 +05:30
|
|
|
describe '.for_lines' do
|
2016-01-29 22:53:50 +05:30
|
|
|
let(:diff) do
|
2016-08-24 12:49:21 +05:30
|
|
|
<<-EOF.strip_heredoc
|
|
|
|
class Test
|
|
|
|
- def initialize(test = true)
|
|
|
|
+ def initialize(test = false)
|
|
|
|
@test = test
|
|
|
|
- if true
|
|
|
|
- @foo = "bar"
|
|
|
|
+ unless false
|
|
|
|
+ @foo = "baz"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOF
|
2016-01-29 22:53:50 +05:30
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
let(:subject) { described_class.for_lines(diff.lines) }
|
2016-01-29 22:53:50 +05:30
|
|
|
|
|
|
|
it 'finds all inline diffs' do
|
|
|
|
expect(subject[0]).to be_nil
|
|
|
|
expect(subject[1]).to eq([25..27])
|
|
|
|
expect(subject[2]).to eq([25..28])
|
|
|
|
expect(subject[3]).to be_nil
|
2016-08-24 12:49:21 +05:30
|
|
|
expect(subject[4]).to eq([5..10])
|
|
|
|
expect(subject[5]).to eq([17..17])
|
|
|
|
expect(subject[6]).to eq([5..15])
|
|
|
|
expect(subject[7]).to eq([17..17])
|
|
|
|
expect(subject[8]).to be_nil
|
2016-01-29 22:53:50 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'can handle unchanged empty lines' do
|
|
|
|
expect { described_class.for_lines(['- bar', '+ baz', '']) }.not_to raise_error
|
|
|
|
end
|
2016-01-29 22:53:50 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
describe "#inline_diffs" do
|
|
|
|
let(:old_line) { "XXX def initialize(test = true)" }
|
|
|
|
let(:new_line) { "YYY def initialize(test = false)" }
|
|
|
|
let(:subject) { described_class.new(old_line, new_line, offset: 3).inline_diffs }
|
|
|
|
|
|
|
|
it "finds the inline diff" do
|
|
|
|
old_diffs, new_diffs = subject
|
|
|
|
|
|
|
|
expect(old_diffs).to eq([26..28])
|
|
|
|
expect(new_diffs).to eq([26..29])
|
|
|
|
end
|
|
|
|
end
|
2016-01-29 22:53:50 +05:30
|
|
|
end
|