package urls import "testing" func TestSubmission(t *testing.T) { got := Submission(42) want := "https://www.furaffinity.net/view/42/" if got != want { t.Errorf("Submission(42) = %q; want %q", got, want) } } func TestUser_LowercasesAndEscapes(t *testing.T) { tests := []struct { name, in, want string }{ {"plain", "SomeUser", "https://www.furaffinity.net/user/someuser/"}, {"trim", " Mixed ", "https://www.furaffinity.net/user/mixed/"}, {"unicode safe", "über", "https://www.furaffinity.net/user/%C3%BCber/"}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { if got := User(tc.in); got != tc.want { t.Errorf("User(%q) = %q; want %q", tc.in, got, tc.want) } }) } } func TestGallery_PageSegments(t *testing.T) { cases := map[int]string{ 1: "https://www.furaffinity.net/gallery/me/", 2: "https://www.furaffinity.net/gallery/me/2/", 10: "https://www.furaffinity.net/gallery/me/10/", } for page, want := range cases { if got := Gallery("me", page); got != want { t.Errorf("Gallery(me, %d) = %q; want %q", page, got, want) } } } func TestMsgSubmissionsCursor(t *testing.T) { got := MsgSubmissionsCursor(65032289) want := "https://www.furaffinity.net/msg/submissions/new~65032289@72/" if got != want { t.Errorf("MsgSubmissionsCursor(65032289) = %q; want %q", got, want) } } func TestAbsoluteCDN(t *testing.T) { cases := map[string]string{ "": "", "https://d.example/x.png": "https://d.example/x.png", "http://d.example/x.png": "http://d.example/x.png", "//d.furaffinity.net/art/x.png": "https://d.furaffinity.net/art/x.png", "/view/1/": "https://www.furaffinity.net/view/1/", "art/foo": "https://www.furaffinity.net/art/foo", } for in, want := range cases { if got := AbsoluteCDN(in); got != want { t.Errorf("AbsoluteCDN(%q) = %q; want %q", in, got, want) } } }