Skip to content

Commit 03adb3a

Browse files
committed
[GITEA] test markdown CleanValue to prevent regression
It will determine how anchors are created and will break existing links otherwise. Adapted from Revert "Make `user-content-* ` consistent with github (go-gitea#26388) (cherry picked from commit 1666fba8f577e11ea234c8a671aeaab1290cfbaf) (cherry picked from commit 48f38280e8b9f34d7c45399f05a670ef3460dac1)
1 parent 26bfc3b commit 03adb3a

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// Copyright 2023 The Forgejo Authors. All rights reserved.
3+
// SPDX-License-Identifier: MIT
4+
package common
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestCleanValue(t *testing.T) {
13+
tests := []struct {
14+
param string
15+
expect string
16+
}{
17+
// Github behavior test cases
18+
{"", ""},
19+
{"test.0.1", "test-0-1"},
20+
{"test(0)", "test-0"},
21+
{"test!1", "test-1"},
22+
{"test:2", "test-2"},
23+
{"test*3", "test-3"},
24+
{"test!4", "test-4"},
25+
{"test:5", "test-5"},
26+
{"test*6", "test-6"},
27+
{"test:6 a", "test-6-a"},
28+
{"test:6 !b", "test-6-b"},
29+
{"test:ad # df", "test-ad-df"},
30+
{"test:ad #23 df 2*/*", "test-ad-23-df-2"},
31+
{"test:ad 23 df 2*/*", "test-ad-23-df-2"},
32+
{"test:ad # 23 df 2*/*", "test-ad-23-df-2"},
33+
{"Anchors in Markdown", "anchors-in-markdown"},
34+
{"a_b_c", "a_b_c"},
35+
{"a-b-c", "a-b-c"},
36+
{"a-b-c----", "a-b-c"},
37+
{"test:6a", "test-6a"},
38+
{"test:a6", "test-a6"},
39+
{"tes a a a a", "tes-a-a-a-a"},
40+
{" tes a a a a ", "tes-a-a-a-a"},
41+
{"Header with \"double quotes\"", "header-with-double-quotes"},
42+
{"Placeholder to force scrolling on link's click", "placeholder-to-force-scrolling-on-link-s-click"},
43+
{"tes()", "tes"},
44+
{"tes(0)", "tes-0"},
45+
{"tes{0}", "tes-0"},
46+
{"tes[0]", "tes-0"},
47+
{"test【0】", "test-0"},
48+
{"tes…@a", "tes-a"},
49+
{"tes¥& a", "tes-a"},
50+
{"tes= a", "tes-a"},
51+
{"tes|a", "tes-a"},
52+
{"tes\\a", "tes-a"},
53+
{"tes/a", "tes-a"},
54+
{"a啊啊b", "a啊啊b"},
55+
{"c🤔️🤔️d", "c-d"},
56+
{"a⚡a", "a-a"},
57+
{"e.~f", "e-f"},
58+
}
59+
for _, test := range tests {
60+
assert.Equal(t, []byte(test.expect), CleanValue([]byte(test.param)), test.param)
61+
}
62+
}

0 commit comments

Comments
 (0)