Files
fish03andClaude Opus 5.5 bef9f8b4ed Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 14:43:16 +07:00

85 lines
3.3 KiB
Go

package playletser
import "testing"
func TestPlayletURLsPreferSlugAndFallbackToIDPath(t *testing.T) {
if got := detailURL("my-show", 12); got != "/detail/my-show" {
t.Fatalf("detailURL with slug = %q", got)
}
if got := detailURL("", 12); got != "/detail/12" {
t.Fatalf("detailURL ID fallback = %q", got)
}
if got := chapterPlayURL("my-show", 12, 3); got != "/play/my-show/3" {
t.Fatalf("chapterPlayURL with slug = %q", got)
}
if got := chapterPlayURL("", 12, 3); got != "/play/12/3" {
t.Fatalf("chapterPlayURL ID fallback = %q", got)
}
if got := themeListURLByKey("wuxia", 10404); got != "/list/wuxia" {
t.Fatalf("themeListURLByKey with slug = %q", got)
}
if got := themeListURLByKey("", 10404); got != "/list/10404" {
t.Fatalf("themeListURLByKey ID fallback = %q", got)
}
if got := categoryURL("editor-picks", 12); got != "/topic/editor-picks" {
t.Fatalf("categoryURL with slug = %q", got)
}
if got := categoryURL("", 12); got != "/topic/12" {
t.Fatalf("categoryURL ID fallback = %q", got)
}
if got := recommendPageURL(12, "editor-picks", 2); got != "/topic/editor-picks/page/2" {
t.Fatalf("recommendPageURL pagination = %q", got)
}
if got := rankPageURL(rankSortNew, 1); got != "/rank/2" {
t.Fatalf("rankPageURL with sort order = %q", got)
}
if got := rankPageURL(rankSortNew, 2); got != "/rank/2/page/2" {
t.Fatalf("rankPageURL pagination = %q", got)
}
q := ListQuery{ThemeSlug: "jiating", SortOrder: sortTodayUpdate, Type: contentTypeNonAdult}
if got := listPageURL(q.ThemeID, q.ThemeSlug, q.SortOrder, 1, q.Type); got != "/list/jiating/2" {
t.Fatalf("listPageURL with theme and sort = %q", got)
}
if got := listPageURL(q.ThemeID, q.ThemeSlug, q.SortOrder, 2, q.Type); got != "/list/jiating/2/page/2" {
t.Fatalf("listPageURL pagination = %q", got)
}
}
func TestListPageURLUsesSortPath(t *testing.T) {
if got := listPageURL(0, "zhichang", sortTodayUpdate, 1, contentTypeNonAdult); got != "/list/zhichang/2" {
t.Fatalf("listPageURL with slug and sort = %q", got)
}
if got := listPageURL(12, "", sortHeat, 1, contentTypeAdult); got != "/list/12/1" {
t.Fatalf("listPageURL ID fallback = %q", got)
}
if got := listPageURL(0, "ai-short-play", sortTodayUpdate, 1, contentTypeAdult); got != "/list/ai-short-play" {
t.Fatalf("listPageURL editorial default = %q", got)
}
if got := listPageURL(0, "ai-short-play", sortHeat, 1, contentTypeAdult); got != "/list/ai-short-play/1" {
t.Fatalf("listPageURL editorial hot = %q", got)
}
}
func TestPlayletDateText(t *testing.T) {
tests := map[string]string{
"2020-09-09 12:30:00": "2020.09.09",
"2026/03/18": "2026.03.18",
"2026.03.18T08:00:00": "2026.03.18",
"": "时间未知",
"1970-01-01": "时间未知",
"2026-13-40": "时间未知",
"invalid-date": "时间未知",
}
for input, want := range tests {
if got := playletDateText(input); got != want {
t.Fatalf("playletDateText(%q) = %q, want %q", input, got, want)
}
}
if got := playletDateText("", "2026-04-05 10:20:30", "2025-01-01"); got != "2026.04.05" {
t.Fatalf("playletDateText fallback = %q, want %q", got, "2026.04.05")
}
if got := playletDateText("invalid-date", "", "2025/08/09"); got != "2025.08.09" {
t.Fatalf("playletDateText valid fallback = %q, want %q", got, "2025.08.09")
}
}