BigW Consortium Gitlab

inline_diff_spec.rb 1.27 KB
Newer Older
Douwe Maan committed
1 2 3
require 'spec_helper'

describe Gitlab::Diff::InlineDiff, lib: true do
4
  describe '.for_lines' do
Douwe Maan committed
5
    let(:diff) do
6 7 8 9 10 11 12 13 14 15 16 17 18
      <<-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
Douwe Maan committed
19 20
    end

21
    let(:subject) { described_class.for_lines(diff.lines) }
Douwe Maan committed
22 23 24 25 26 27

    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
28 29 30 31 32
      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
Douwe Maan committed
33 34
    end
  end
35 36 37 38 39 40 41 42 43 44 45 46 47

  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
Douwe Maan committed
48
end