debian-mirror-gitlab/spec/lib/gitlab/diff/parallel_diff_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
2.3 KiB
Ruby
Raw Normal View History

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::ParallelDiff do
2016-01-29 22:53:50 +05:30
include RepoHelpers
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
2016-01-29 22:53:50 +05:30
let(:repository) { project.repository }
let(:commit) { project.commit(sample_commit.id) }
2016-09-13 17:45:13 +05:30
let(:diffs) { commit.raw_diffs }
2016-01-29 22:53:50 +05:30
let(:diff) { diffs.first }
2016-08-24 12:49:21 +05:30
let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: commit.diff_refs, repository: repository) }
2020-01-01 13:55:28 +05:30
2016-01-29 22:53:50 +05:30
subject { described_class.new(diff_file) }
describe '#parallelize' do
2017-08-17 22:00:37 +05:30
it 'returns an array of arrays containing the parsed diff' do
2016-09-13 17:45:13 +05:30
diff_lines = diff_file.highlighted_diff_lines
expected = [
# Unchanged lines
{ left: diff_lines[0], right: diff_lines[0] },
{ left: diff_lines[1], right: diff_lines[1] },
{ left: diff_lines[2], right: diff_lines[2] },
{ left: diff_lines[3], right: diff_lines[3] },
{ left: diff_lines[4], right: diff_lines[5] },
{ left: diff_lines[6], right: diff_lines[6] },
{ left: diff_lines[7], right: diff_lines[7] },
{ left: diff_lines[8], right: diff_lines[8] },
# Changed lines
{ left: diff_lines[9], right: diff_lines[11] },
{ left: diff_lines[10], right: diff_lines[12] },
# Added lines
{ left: nil, right: diff_lines[13] },
{ left: nil, right: diff_lines[14] },
{ left: nil, right: diff_lines[15] },
{ left: nil, right: diff_lines[16] },
{ left: nil, right: diff_lines[17] },
{ left: nil, right: diff_lines[18] },
# Unchanged lines
{ left: diff_lines[19], right: diff_lines[19] },
{ left: diff_lines[20], right: diff_lines[20] },
{ left: diff_lines[21], right: diff_lines[21] },
{ left: diff_lines[22], right: diff_lines[22] },
{ left: diff_lines[23], right: diff_lines[23] },
{ left: diff_lines[24], right: diff_lines[24] },
{ left: diff_lines[25], right: diff_lines[25] },
# Added line
{ left: nil, right: diff_lines[26] },
# Unchanged lines
{ left: diff_lines[27], right: diff_lines[27] },
{ left: diff_lines[28], right: diff_lines[28] },
{ left: diff_lines[29], right: diff_lines[29] }
]
expect(subject.parallelize).to eq(expected)
2016-01-29 22:53:50 +05:30
end
end
end