22 lines
613 B
Go
22 lines
613 B
Go
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
|||
|
|
// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
||
|
|
|
||
|
|
package fediverse
|
||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
func TestValid(t *testing.T) {
|
||
|
|
good := []string{"@user@host.social", "@a@b", "@petr@social.example.org"}
|
||
|
|
for _, handle := range good {
|
||
|
|
if !Valid(handle) {
|
||
|
|
t.Errorf("Valid(%q) = false, want true", handle)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
bad := []string{"", "user@host", "@user", "@@host", "@user@", "@user @host", "@user@ho st", "u@h"}
|
||
|
|
for _, handle := range bad {
|
||
|
|
if Valid(handle) {
|
||
|
|
t.Errorf("Valid(%q) = true, want false", handle)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|