blob: f448f5b5eb6c4eba903784b0d494507c7d64c4e9 (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::WordDiff::LineProcessor do
subject(:line_processor) { described_class.new(line) }
describe '#extract' do
subject(:segment) { line_processor.extract }
context 'when line is a diff hunk' do
let(:line) { "@@ -1,14 +1,13 @@\n" }
it 'returns DiffHunk segment' do
expect(segment).to be_a(Gitlab::WordDiff::Segments::DiffHunk)
expect(segment.to_s).to eq('@@ -1,14 +1,13 @@')
end
end
context 'when line has a newline delimiter' do
let(:line) { "~\n" }
it 'returns Newline segment' do
expect(segment).to be_a(Gitlab::WordDiff::Segments::Newline)
expect(segment.to_s).to eq('')
end
end
context 'when line has only space' do
let(:line) { " \n" }
it 'returns nil' do
is_expected.to be_nil
end
end
context 'when line has content' do
let(:line) { "+New addition\n" }
it 'returns Chunk segment' do
expect(segment).to be_a(Gitlab::WordDiff::Segments::Chunk)
expect(segment.to_s).to eq('New addition')
end
end
end
end
|