Files
mtusi2026lab6/internal/service/validate_test.go
T

40 lines
1.1 KiB
Go
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package service
import (
"strings"
"testing"
)
func TestValidatePassword(t *testing.T) {
cases := []struct {
name string
in string
want bool
}{
{"обычный", "correct-horse-12", true},
{"ровно 12", strings.Repeat("a", 12), true},
{"128 code points", strings.Repeat("я", 128), true},
{"двоеточие допустимо", "pass:word:1234", true},
{"пробелы внутри допустимы", " pass word ", true},
{"короче 12", strings.Repeat("a", 11), false},
{"длиннее 128", strings.Repeat("a", 129), false},
{"12 пробелов", strings.Repeat(" ", 12), false},
{"пробельные символы разных видов", strings.Repeat(" \t\n ", 4), false},
{"пусто", "", false},
}
for _, c := range cases {
if got := validatePassword(c.in); got != c.want {
t.Errorf("%s: validatePassword(%q) = %v, want %v", c.name, c.in, got, c.want)
}
}
}
func TestValidateText(t *testing.T) {
if validateText(strings.Repeat(" ", 5)) {
t.Error("whitespace-only text must be rejected")
}
if !validateText("привет") {
t.Error("normal text must be accepted")
}
}