code.gitea.io/gitea@v1.22.3/modules/markup/common/footnote_test.go (about)

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