-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_test.go
More file actions
53 lines (47 loc) · 1.28 KB
/
utils_test.go
File metadata and controls
53 lines (47 loc) · 1.28 KB
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
package main
import (
"regexp"
"testing"
)
func TestGenerateAnonymousNameFormat(t *testing.T) {
name := generateAnonymousName()
re := regexp.MustCompile(`^Anonymous\d{4}$`)
if !re.MatchString(name) {
t.Fatalf("unexpected anonymous name format: %q", name)
}
}
func TestNormalizeUsername(t *testing.T) {
got := normalizeUsername(" test-user ")
if got != "test-user" {
t.Fatalf("normalizeUsername() = %q, want %q", got, "test-user")
}
}
func TestIsValidUsername(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{name: "too short", input: "ab", want: false},
{name: "too long", input: "123456789012345678901", want: false},
{name: "valid ascii", input: "user_01", want: true},
{name: "valid unicode", input: "Иван-7", want: true},
{name: "invalid symbol", input: "bad!name", want: false},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := isValidUsername(tc.input)
if got != tc.want {
t.Fatalf("isValidUsername(%q) = %v, want %v", tc.input, got, tc.want)
}
})
}
}
func TestSanitizeForTerminal(t *testing.T) {
input := "\x1b[31mRed\x1b[0m\nline\t\x00text"
got := sanitizeForTerminal(input)
want := "Red\nline\ttext"
if got != want {
t.Fatalf("sanitizeForTerminal() = %q, want %q", got, want)
}
}