BigW Consortium Gitlab

parallel_diff_spec.rb 2.23 KB
Newer Older
1 2 3 4
require 'spec_helper'

describe Gitlab::Diff::ParallelDiff, lib: true do
  include RepoHelpers
Douwe Maan committed
5

6 7 8
  let(:project) { create(:project) }
  let(:repository) { project.repository }
  let(:commit) { project.commit(sample_commit.id) }
9
  let(:diffs) { commit.raw_diffs }
10
  let(:diff) { diffs.first }
11
  let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: commit.diff_refs, repository: repository) }
12 13 14 15
  subject { described_class.new(diff_file) }

  describe '#parallelize' do
    it 'should return an array of arrays containing the parsed diff' do
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
      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)
59 60 61
    end
  end
end