summaryrefslogtreecommitdiffstats
path: root/routers/api/packages/generic/generic_test.go
blob: 1acaafe576ae967cbed545691ac3fce46a10176f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// 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)
	}
}