Welcome to mirror list, hosted at ThFree Co, Russian Federation.

chunk_collection_spec.rb « word_diff « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f76c4213c19070c24dcd21c6752a6c4277a2b20b (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::WordDiff::ChunkCollection do
  subject(:collection) { described_class.new }

  describe '#add' do
    it 'adds elements to the chunk collection' do
      collection.add('Hello')
      collection.add(' World')

      expect(collection.content).to eq('Hello World')
    end
  end

  describe '#content' do
    subject { collection.content }

    context 'when no elements in the collection' do
      it { is_expected.to eq('') }
    end

    context 'when elements exist' do
      before do
        collection.add('Hi')
        collection.add(' GitLab!')
      end

      it { is_expected.to eq('Hi GitLab!') }
    end
  end

  describe '#reset' do
    it 'clears the collection' do
      collection.add('1')
      collection.add('2')

      collection.reset

      expect(collection.content).to eq('')
    end
  end

  describe '#marker_ranges' do
    let(:chunks) do
      [
        Gitlab::WordDiff::Segments::Chunk.new(' Hello '),
        Gitlab::WordDiff::Segments::Chunk.new('-World'),
        Gitlab::WordDiff::Segments::Chunk.new('+GitLab'),
        Gitlab::WordDiff::Segments::Chunk.new('+!!!')
      ]
    end

    it 'returns marker ranges for every chunk with changes' do
      chunks.each { |chunk| collection.add(chunk) }

      expect(collection.marker_ranges).to eq(
        [
          Gitlab::MarkerRange.new(6, 10, mode: :deletion),
          Gitlab::MarkerRange.new(11, 16, mode: :addition),
          Gitlab::MarkerRange.new(17, 19, mode: :addition)
        ]
      )
    end
  end
end