# frozen_string_literal: true require 'fast_spec_helper' RSpec.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:, mode:| %(#{text}).html_safe 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 } let(:regexp) { /<[a-z]>/ } subject do described_class.new(raw, rich).mark(regexp) do |text, left:, right:, mode:| %(#{text}).html_safe end end it 'marks the matches' do expect(subject).to eq(%(a <b> <c> d)) expect(subject).to be_html_safe end context 'with a Gitlab::UntrustedRegexp' do let(:regexp) { Gitlab::UntrustedRegexp.new('<[a-z]>') } it 'marks the matches' do expect(subject).to eq(%(a <b> <c> d)) expect(subject).to be_html_safe end end end end end