[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 (#26388)

(cherry picked from commit 1666fba8f577e11ea234c8a671aeaab1290cfbaf)
(cherry picked from commit 48f38280e8b9f34d7c45399f05a670ef3460dac1)
(cherry picked from commit 03adb3a2b46081e183738a86ca3d54bf730de0bd)
(cherry picked from commit a0ad36f0ad5d99896d5319e9aca11d0cf0ce23ee)
(cherry picked from commit 3aac9900640da2eeaac7950d14132361923d1a69)
(cherry picked from commit 137daabc9b437c9bd37b45a80e44880d0ac44656)
(cherry picked from commit b438aed4c1ff57985fcbe3687fc54c54ba680464)
(cherry picked from commit 90b36f2e67acec00870005647b906ea69ae11d27)
This commit is contained in:
Earl Warren 2023-12-13 17:42:34 +01:00
parent 7b79294684
commit 6b5bfffe5d
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -0,0 +1,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"},
{"test4", "test-4"},
{"test5", "test-5"},
{"test*6", "test-6"},
{"test6 a", "test-6-a"},
{"test6 !b", "test-6-b"},
{"testad # df", "test-ad-df"},
{"testad #23 df 2*/*", "test-ad-23-df-2"},
{"testad 23 df 2*/*", "test-ad-23-df-2"},
{"testad # 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"},
{"test6a", "test-6a"},
{"testa6", "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"},
{"tes0", "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)
}
}