summaryrefslogtreecommitdiffstats
path: root/modules/markup/common/footnote_test.go
blob: 62763c56220d1f644f3862c962fff1fe571592f8 (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
// Copyright 2023 The Gitea Authors. All rights reserved.
// Copyright 2023 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package common

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestCleanValue(t *testing.T) {
	tests := []struct {
		param  string
		expect string
	}{
		// Github behavior test cases
		{"", ""},
		{"test.0.1", "test-0-1"},
		{"test(0)", "test-0"},
		{"test!1", "test-1"},
		{"test:2", "test-2"},
		{"test*3", "test-3"},
		{"test!4", "test-4"},
		{"test:5", "test-5"},
		{"test*6", "test-6"},
		{"test:6 a", "test-6-a"},
		{"test:6 !b", "test-6-b"},
		{"test:ad # df", "test-ad-df"},
		{"test:ad #23 df 2*/*", "test-ad-23-df-2"},
		{"test:ad 23 df 2*/*", "test-ad-23-df-2"},
		{"test:ad # 23 df 2*/*", "test-ad-23-df-2"},
		{"Anchors in Markdown", "anchors-in-markdown"},
		{"a_b_c", "a_b_c"},
		{"a-b-c", "a-b-c"},
		{"a-b-c----", "a-b-c"},
		{"test:6a", "test-6a"},
		{"test:a6", "test-a6"},
		{"tes a a   a  a", "tes-a-a-a-a"},
		{"  tes a a   a  a  ", "tes-a-a-a-a"},
		{"Header with \"double quotes\"", "header-with-double-quotes"},
		{"Placeholder to force scrolling on link's click", "placeholder-to-force-scrolling-on-link-s-click"},
		{"tes()", "tes"},
		{"tes(0)", "tes-0"},
		{"tes{0}", "tes-0"},
		{"tes[0]", "tes-0"},
		{"test【0】", "test-0"},
		{"tes…@a", "tes-a"},
		{"tes¥& a", "tes-a"},
		{"tes= a", "tes-a"},
		{"tes|a", "tes-a"},
		{"tes\\a", "tes-a"},
		{"tes/a", "tes-a"},
		{"a啊啊b", "a啊啊b"},
		{"c🤔️🤔️d", "c-d"},
		{"a⚡a", "a-a"},
		{"e.~f", "e-f"},
	}
	for _, test := range tests {
		assert.Equal(t, []byte(test.expect), CleanValue([]byte(test.param)), test.param)
	}
}