summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/word_diff/segments/chunk_spec.rb
blob: 797cc42a03c507454ae2534fcee2992926435446 (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
52
53
# frozen_string_literal: true

require 'spec_helper'

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

  let(:line) { ' Hello' }

  describe '#removed?' do
    subject { chunk.removed? }

    it { is_expected.to be_falsey }

    context 'when line starts with "-"' do
      let(:line) { '-Removed' }

      it { is_expected.to be_truthy }
    end
  end

  describe '#added?' do
    subject { chunk.added? }

    it { is_expected.to be_falsey }

    context 'when line starts with "+"' do
      let(:line) { '+Added' }

      it { is_expected.to be_truthy }
    end
  end

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

    it 'removes lead string modifier' do
      is_expected.to eq('Hello')
    end

    context 'when chunk is empty' do
      let(:line) { '' }

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

  describe '#length' do
    subject { chunk.length }

    it { is_expected.to eq('Hello'.length) }
  end
end