verstak/internal/core/templates/safename_test.go

42 lines
1005 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package templates
import (
"testing"
)
func TestSafeDisplayNameToPathSegment(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"Разработка серверной", "Разработка серверной"},
{"Проект/Подпроект", роект_Подпроект"},
{"File:Name*Test?\"Test", "File Name Test Test"},
{"../../evil", "_._.._evil"},
{".hidden", "_hidden"},
{" spaced ", "spaced"},
{"", "Без названия"},
{"AB", "AB"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := SafeDisplayNameToPathSegment(tt.input)
if got != tt.expected {
t.Errorf("SafeDisplayNameToPathSegment(%q) = %q, want %q", tt.input, got, tt.expected)
}
})
}
}
func TestSafeDisplayNameToPathSegment_Long(t *testing.T) {
long := ""
for i := 0; i < 300; i++ {
long += "a"
}
got := SafeDisplayNameToPathSegment(long)
if len(got) > 200 {
t.Errorf("expected max 200 chars, got %d", len(got))
}
}