package client import "testing" func TestParseInviteLink(t *testing.T) { cases := []struct { link string base, tsec, name string }{ // The minted shape (invite.js buildInviteFragment): e1., optional ~name. {"https://x.11ch.at/join/Paul#e1.abc123", "https://x.11ch.at", "abc123", ""}, {"https://x.11ch.at/join/Paul#e1.abc123~Ciara%20B", "https://x.11ch.at", "abc123", "Ciara B"}, // Older links carry a bare T. {"https://x.11ch.at/join/Paul#abc123", "https://x.11ch.at", "abc123", ""}, // Whitespace from a sloppy paste. {" https://x.11ch.at/join/Paul#e1.abc123\n", "https://x.11ch.at", "abc123", ""}, } for _, c := range cases { got, err := ParseInviteLink(c.link) if err != nil { t.Errorf("ParseInviteLink(%q): %v", c.link, err) continue } if got.Base != c.base || got.T != c.tsec || got.Name != c.name { t.Errorf("ParseInviteLink(%q) = %+v, want base=%q T=%q name=%q", c.link, got, c.base, c.tsec, c.name) } } for _, bad := range []string{"", "not a link", "https://x.11ch.at/join/Paul", "https://x.11ch.at/join/Paul#e1."} { if _, err := ParseInviteLink(bad); err == nil { t.Errorf("ParseInviteLink(%q) should fail", bad) } } }