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/utils/markdown_spec.rb')
-rw-r--r--spec/lib/gitlab/utils/markdown_spec.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/lib/gitlab/utils/markdown_spec.rb b/spec/lib/gitlab/utils/markdown_spec.rb
new file mode 100644
index 00000000000..001ff5bc487
--- /dev/null
+++ b/spec/lib/gitlab/utils/markdown_spec.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Utils::Markdown do
+ let(:klass) do
+ Class.new do
+ include Gitlab::Utils::Markdown
+ end
+ end
+
+ subject(:object) { klass.new }
+
+ describe '#string_to_anchor' do
+ subject { object.string_to_anchor(string) }
+
+ let(:string) { 'My Header' }
+
+ it 'converts string to anchor' do
+ is_expected.to eq 'my-header'
+ end
+
+ context 'when string has punctuation' do
+ let(:string) { 'My, Header!' }
+
+ it 'removes punctuation' do
+ is_expected.to eq 'my-header'
+ end
+ end
+
+ context 'when string starts and ends with spaces' do
+ let(:string) { ' My Header ' }
+
+ it 'removes extra spaces' do
+ is_expected.to eq 'my-header'
+ end
+ end
+
+ context 'when string has multiple spaces and dashes in the middle' do
+ let(:string) { 'My - - - Header' }
+
+ it 'removes consecutive dashes' do
+ is_expected.to eq 'my-header'
+ end
+ end
+
+ context 'when string contains only digits' do
+ let(:string) { '123' }
+
+ it 'adds anchor prefix' do
+ is_expected.to eq 'anchor-123'
+ end
+ end
+
+ context 'when string is empty' do
+ let(:string) { '' }
+
+ it 'returns an empty string' do
+ is_expected.to eq ''
+ end
+ end
+ end
+end