1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-07 19:17:21 +00:00

Fix some trivial problems (#34579) (#34585)

Backport #34579 by wxiaoguang

See the comments

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot
2025-06-03 01:31:35 +08:00
committed by GitHub
parent f9a0b077a7
commit 7baa6fa47c
8 changed files with 46 additions and 12 deletions

View File

@ -7,6 +7,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var giteaTemplate = []byte(`
@ -65,3 +66,26 @@ func TestFileNameSanitize(t *testing.T) {
assert.Equal(t, "_", fileNameSanitize("\u0000"))
assert.Equal(t, "目标", fileNameSanitize("目标"))
}
func TestTransformers(t *testing.T) {
cases := []struct {
name string
expected string
}{
{"SNAKE", "abc_def_xyz"},
{"KEBAB", "abc-def-xyz"},
{"CAMEL", "abcDefXyz"},
{"PASCAL", "AbcDefXyz"},
{"LOWER", "abc_def-xyz"},
{"UPPER", "ABC_DEF-XYZ"},
{"TITLE", "Abc_def-Xyz"},
}
input := "Abc_Def-XYZ"
assert.Len(t, defaultTransformers, len(cases))
for i, c := range cases {
tf := defaultTransformers[i]
require.Equal(t, c.name, tf.Name)
assert.Equal(t, c.expected, tf.Transform(input), "case %s", c.name)
}
}