require 'spec_helper'
describe Gitlab::StringRegexMarker do
describe '#mark' do
context 'with a single occurrence' do
let(:raw) { %{"name": "AFNetworking"} }
let(:rich) { %{"name": "AFNetworking"}.html_safe }
subject do
described_class.new(raw, rich).mark(/"[^"]+":\s*"(?[^"]+)"/, group: :name) do |text, left:, right:|
%{#{text}}
end
end
it 'marks the match' do
expect(subject).to eq(%{"name": "AFNetworking"})
expect(subject).to be_html_safe
end
end
context 'with multiple occurrences' do
let(:raw) { %{a d} }
let(:rich) { %{a <b> <c> d}.html_safe }
subject do
described_class.new(raw, rich).mark(/<[a-z]>/) do |text, left:, right:|
%{#{text}}
end
end
it 'marks the matches' do
expect(subject).to eq(%{a <b> <c> d})
expect(subject).to be_html_safe
end
end
end
end