You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package handler
import (
"strings"
"testing"
"unicode/utf8"
"golang.org/x/text/unicode/norm"
)
func TestIsValidHeroName_NFCCombiningY(t *testing.T) {
// Й в NFD: и + U+0306; без NFC вторая руна не входит в блок кириллицы и имя отклонялось.
raw := "\u0438\u0306a"
nfc := norm.NFC.String(strings.TrimSpace(raw))
if nfc != "\u0439a" && utf8.RuneCountInString(nfc) != 2 {
t.Fatalf("unexpected NFC: %q (%d runes)", nfc, utf8.RuneCountInString(nfc))
}
if !isValidHeroName(nfc) {
t.Fatal("expected valid name with й (NFC)")
}
}
func TestIsValidHeroName_runeLengthNotBytes(t *testing.T) {
// 9 кириллических букв = 18 байт UTF-8, но 9 символов — должно быть допустимо.
name := "Абвгдейкz"
if utf8.RuneCountInString(name) != 9 {
t.Fatal("test setup")
}
if len(name) <= 16 {
t.Fatal("test needs >16 bytes with <=16 runes")
}
if !isValidHeroName(name) {
t.Fatal("expected valid: length limit is runes, not UTF-8 bytes")
}
}