Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
111 lines
3.9 KiB
Go
111 lines
3.9 KiB
Go
package playletser
|
|
|
|
import "testing"
|
|
|
|
func TestFooterLinkURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
raw string
|
|
want string
|
|
}{
|
|
{name: "关于我们", raw: "/richtext/关于我们", want: "/richtext/关于我们/"},
|
|
{name: "帮助中心", raw: "/richtext/帮助中心", want: "/richtext/帮助中心/"},
|
|
{name: "隐私政策", raw: "/richtext/privacy", want: "/richtext/privacy/"},
|
|
{name: "问题反馈", raw: "/feedback", want: "/feedback/"},
|
|
{name: "用户中心", raw: "/user-center/", want: "/user-center/"},
|
|
{name: "合作伙伴", raw: "https://example.com", want: "https://example.com"},
|
|
{name: "HTTPS外链", raw: "HTTPS://Example.COM", want: "HTTPS://Example.COM"},
|
|
{name: "关于我们", raw: "", want: ""},
|
|
{name: "关于我们", raw: "/", want: ""},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name+" "+tt.raw, func(t *testing.T) {
|
|
if got := footerLinkURL(tt.name, tt.raw); got != tt.want {
|
|
t.Fatalf("footerLinkURL(%q, %q) = %q, want %q", tt.name, tt.raw, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFooterLinkIsExternal(t *testing.T) {
|
|
if !footerLinkIsExternal("http://a.com") || !footerLinkIsExternal("HTTPS://A.COM") {
|
|
t.Fatal("http(s) URLs should be external")
|
|
}
|
|
if footerLinkIsExternal("/richtext/关于我们/") || footerLinkIsExternal("/feedback/") {
|
|
t.Fatal("internal paths should not be external")
|
|
}
|
|
}
|
|
|
|
func TestFooterContactURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
value string
|
|
gmail string
|
|
telegram string
|
|
customer string
|
|
want string
|
|
}{
|
|
{name: "E-mail", value: "hello@example.com", want: "mailto:hello@example.com"},
|
|
{name: "邮箱", gmail: "support@example.com", want: "mailto:support@example.com"},
|
|
{name: "商务合作", value: "立即联系", customer: "service.example.com", want: "https://service.example.com"},
|
|
{name: "商务合作", value: "business@example.com", want: "mailto:business@example.com"},
|
|
{name: "官方群", value: "立即加入", telegram: "https://t.me/example", want: "https://t.me/example"},
|
|
{name: "官方群", value: "t.me/example", want: "https://t.me/example"},
|
|
{name: "工作时间", value: "10:00-18:00", want: ""},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name+tt.value, func(t *testing.T) {
|
|
got := footerContactURL(tt.name, tt.value, tt.gmail, tt.telegram, tt.customer)
|
|
if got != tt.want {
|
|
t.Fatalf("footerContactURL(%q, %q) = %q, want %q", tt.name, tt.value, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFooterContactValue(t *testing.T) {
|
|
for _, value := range []string{"立即联系", "立即加入", " 立即加入 "} {
|
|
if got := footerContactValue(value); got != "" {
|
|
t.Fatalf("footerContactValue(%q) = %q, want empty", value, got)
|
|
}
|
|
}
|
|
if got := footerContactValue("hello@example.com"); got != "hello@example.com" {
|
|
t.Fatalf("footerContactValue(email) = %q", got)
|
|
}
|
|
if got := footerContactValue("立即联系:https://t1t1.com"); got != "https://t1t1.com" {
|
|
t.Fatalf("footerContactValue(business URL) = %q", got)
|
|
}
|
|
if got := footerContactValue("立即加入: https://t.me/fuliqun_91sp"); got != "https://t.me/fuliqun_91sp" {
|
|
t.Fatalf("footerContactValue(group URL) = %q", got)
|
|
}
|
|
}
|
|
|
|
func TestFooterContactName(t *testing.T) {
|
|
tests := map[string]string{
|
|
"商务合作:立即联系": "商务合作",
|
|
"官方群:立即加入": "官方群",
|
|
"立即联系:商务合作": "商务合作",
|
|
" E-mail ": "E-mail",
|
|
}
|
|
for input, want := range tests {
|
|
if got := footerContactName(input); got != want {
|
|
t.Fatalf("footerContactName(%q) = %q, want %q", input, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNavDisplayURL(t *testing.T) {
|
|
tests := map[string]string{
|
|
"https://91lvmao0000.com/": "91lvmao0000.com",
|
|
"http://example.com/path/": "example.com/path",
|
|
"example.com": "example.com",
|
|
}
|
|
for input, want := range tests {
|
|
if got := navDisplayURL(input); got != want {
|
|
t.Fatalf("navDisplayURL(%q) = %q, want %q", input, got, want)
|
|
}
|
|
}
|
|
}
|