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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/word_diff/line_processor_spec.rb')
-rw-r--r--spec/lib/gitlab/word_diff/line_processor_spec.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/lib/gitlab/word_diff/line_processor_spec.rb b/spec/lib/gitlab/word_diff/line_processor_spec.rb
new file mode 100644
index 00000000000..f448f5b5eb6
--- /dev/null
+++ b/spec/lib/gitlab/word_diff/line_processor_spec.rb
@@ -0,0 +1,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