mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
949 B
66 lines
949 B
8 months ago
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||
|
// SPDX-License-Identifier: MIT
|
||
|
|
||
|
package generic
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestValidatePackageName(t *testing.T) {
|
||
|
bad := []string{
|
||
|
"",
|
||
|
".",
|
||
|
"..",
|
||
|
"-",
|
||
|
"a?b",
|
||
|
"a b",
|
||
|
"a/b",
|
||
|
}
|
||
|
for _, name := range bad {
|
||
|
assert.False(t, isValidPackageName(name), "bad=%q", name)
|
||
|
}
|
||
|
|
||
|
good := []string{
|
||
|
"a",
|
||
|
"1",
|
||
|
"a-",
|
||
|
"a_b",
|
||
|
"c.d+",
|
||
|
}
|
||
|
for _, name := range good {
|
||
|
assert.True(t, isValidPackageName(name), "good=%q", name)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestValidateFileName(t *testing.T) {
|
||
|
bad := []string{
|
||
|
"",
|
||
|
".",
|
||
|
"..",
|
||
|
"a?b",
|
||
|
"a/b",
|
||
|
" a",
|
||
|
"a ",
|
||
|
}
|
||
|
for _, name := range bad {
|
||
|
assert.False(t, isValidFileName(name), "bad=%q", name)
|
||
|
}
|
||
|
|
||
|
good := []string{
|
||
|
"-",
|
||
|
"a",
|
||
|
"1",
|
||
|
"a-",
|
||
|
"a_b",
|
||
|
"a b",
|
||
|
"c.d+",
|
||
|
`-_+=:;.()[]{}~!@#$%^& aA1`,
|
||
|
}
|
||
|
for _, name := range good {
|
||
|
assert.True(t, isValidFileName(name), "good=%q", name)
|
||
|
}
|
||
|
}
|