summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/word_diff/segments/chunk_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/lib/gitlab/word_diff/segments/chunk_spec.rb
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/lib/gitlab/word_diff/segments/chunk_spec.rb')
-rw-r--r--spec/lib/gitlab/word_diff/segments/chunk_spec.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/lib/gitlab/word_diff/segments/chunk_spec.rb b/spec/lib/gitlab/word_diff/segments/chunk_spec.rb
new file mode 100644
index 00000000000..797cc42a03c
--- /dev/null
+++ b/spec/lib/gitlab/word_diff/segments/chunk_spec.rb
@@ -0,0 +1,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