23 lines
887 B
Go
23 lines
887 B
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestFriendlyHistoryTitle(t *testing.T) {
|
|
cases := []struct {
|
|
name, title, rawURL, want string
|
|
}{
|
|
{name: "real title", title: "Docker Documentation", rawURL: "https://www.docker.com/docs/", want: "Docker Documentation"},
|
|
{name: "missing title", rawURL: "https://www.docker.com/", want: "docker.com"},
|
|
{name: "url title", title: "https://www.docker.com/", rawURL: "https://www.docker.com/", want: "docker.com"},
|
|
{name: "http url title", title: "http://example.org/a", rawURL: "http://example.org/a", want: "example.org"},
|
|
{name: "invalid fallback", rawURL: "://", want: "历史站点"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if got := friendlyHistoryTitle(tc.title, tc.rawURL); got != tc.want {
|
|
t.Fatalf("friendlyHistoryTitle(%q, %q) = %q; want %q", tc.title, tc.rawURL, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|