blob: acc5bd47c8c72130f01c615f03567ba1c75997c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# 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 has a product suffix' do
%w[CORE STARTER PREMIUM ULTIMATE FREE BRONZE SILVER GOLD].each do |tier|
['', ' ONLY', ' SELF', ' SASS'].each do |modifier|
context "#{tier}#{modifier}" do
let(:string) { "My Header (#{tier}#{modifier})" }
it 'ignores a product suffix' do
is_expected.to eq 'my-header'
end
context 'with "*" around a product suffix' do
let(:string) { "My Header **(#{tier}#{modifier})**" }
it 'ignores a product suffix' do
is_expected.to eq 'my-header'
end
end
end
end
end
end
context 'when string is empty' do
let(:string) { '' }
it 'returns an empty string' do
is_expected.to eq ''
end
end
end
end
|