summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/string_range_marker_spec.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-07-10 15:10:59 -0500
committerDouwe Maan <douwe@selenight.nl>2017-05-10 08:26:21 -0500
commite179707844b043fac6f81a30f82e5f4ba446abde (patch)
treed8f63cdd15cf4ffe19260f687c6a803832e9686d /spec/lib/gitlab/string_range_marker_spec.rb
parent09c2aab4aa4661b147545e2c41b6a0100fc57b11 (diff)
downloadgitlab-ce-e179707844b043fac6f81a30f82e5f4ba446abde.tar.gz
Extract generic parts of Gitlab::Diff::InlineDiffMarker
Diffstat (limited to 'spec/lib/gitlab/string_range_marker_spec.rb')
-rw-r--r--spec/lib/gitlab/string_range_marker_spec.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/lib/gitlab/string_range_marker_spec.rb b/spec/lib/gitlab/string_range_marker_spec.rb
new file mode 100644
index 00000000000..45b4d4af206
--- /dev/null
+++ b/spec/lib/gitlab/string_range_marker_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe Gitlab::StringRangeMarker, lib: true do
+ describe '#mark' do
+ context "when the rich text is html safe" do
+ let(:raw) { "abc <def>" }
+ let(:rich) { %{<span class="abc">abc</span><span class="space"> </span><span class="def">&lt;def&gt;</span>}.html_safe }
+ let(:inline_diffs) { [2..5] }
+ let(:subject) do
+ described_class.new(raw, rich).mark(inline_diffs) do |text, left:, right:|
+ "LEFT#{text}RIGHT"
+ end
+ end
+
+ it 'marks the inline diffs' do
+ expect(subject).to eq(%{<span class="abc">abLEFTcRIGHT</span><span class="space">LEFT RIGHT</span><span class="def">LEFT&lt;dRIGHTef&gt;</span>})
+ expect(subject).to be_html_safe
+ end
+ end
+
+ context "when the rich text is not html safe" do
+ let(:raw) { "abc <def>" }
+ let(:inline_diffs) { [2..5] }
+ let(:subject) do
+ described_class.new(raw).mark(inline_diffs) do |text, left:, right:|
+ "LEFT#{text}RIGHT"
+ end
+ end
+
+ it 'marks the inline diffs' do
+ expect(subject).to eq(%{abLEFTc &lt;dRIGHTef&gt;})
+ expect(subject).to be_html_safe
+ end
+ end
+ end
+end