28 lines
822 B
Go
28 lines
822 B
Go
package viral
|
|
|
|
import "testing"
|
|
|
|
func TestExtractUsernames(t *testing.T) {
|
|
blob := `See https://www.threads.net/@creator_one and threads.com/@creator_two/posts/abc`
|
|
got := extractUsernames(blob)
|
|
if len(got) != 2 {
|
|
t.Fatalf("expected 2 usernames, got %d (%v)", len(got), got)
|
|
}
|
|
}
|
|
|
|
func TestIsValidUsernameRejectsReserved(t *testing.T) {
|
|
if isValidUsername("login") {
|
|
t.Fatal("reserved username should be rejected")
|
|
}
|
|
if !isValidUsername("real_creator") {
|
|
t.Fatal("valid username rejected")
|
|
}
|
|
}
|
|
|
|
func TestBuildAccountDiscoverQueriesCapsAtTwo(t *testing.T) {
|
|
queries := buildAccountDiscoverQueries("轉職", "想找語錄", []string{"支柱A", "支柱B", "支柱C"})
|
|
if len(queries) > maxAccountDiscoverQueries {
|
|
t.Fatalf("expected at most %d queries, got %d", maxAccountDiscoverQueries, len(queries))
|
|
}
|
|
}
|