summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/word_diff/segments/diff_hunk_spec.rb
blob: a65f55c716fa51e37f8a1b34af0cadad9a178238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::WordDiff::Segments::DiffHunk do
  subject(:diff_hunk) { described_class.new(line) }

  let(:line) { '@@ -3,14 +4,13 @@' }

  describe '#pos_old' do
    subject { diff_hunk.pos_old }

    it { is_expected.to eq 3 }

    context 'when diff hunk is broken' do
      let(:line) { '@@ ??? @@' }

      it { is_expected.to eq 0 }
    end
  end

  describe '#pos_new' do
    subject { diff_hunk.pos_new }

    it { is_expected.to eq 4 }

    context 'when diff hunk is broken' do
      let(:line) { '@@ ??? @@' }

      it { is_expected.to eq 0 }
    end
  end

  describe '#first_line?' do
    subject { diff_hunk.first_line? }

    it { is_expected.to be_falsey }

    context 'when diff hunk located on the first line' do
      let(:line) { '@@ -1,14 +1,13 @@' }

      it { is_expected.to be_truthy }
    end
  end

  describe '#to_s' do
    subject { diff_hunk.to_s }

    it { is_expected.to eq(line) }
  end
end