eleven / ocho Public

Clone
git clone https://amadan.net/eleven/ocho

Plain git — no account needed to clone.

Download

Download this file

1package client
2
3import "testing"
4
5func TestParseInviteLink(t *testing.T) {
6 cases := []struct {
7 link string
8 base, tsec, name string
9 }{
10 // The minted shape (invite.js buildInviteFragment): e1.<T>, optional ~name.
11 {"https://x.11ch.at/join/Paul#e1.abc123", "https://x.11ch.at", "abc123", ""},
12 {"https://x.11ch.at/join/Paul#e1.abc123~Ciara%20B", "https://x.11ch.at", "abc123", "Ciara B"},
13 // Older links carry a bare T.
14 {"https://x.11ch.at/join/Paul#abc123", "https://x.11ch.at", "abc123", ""},
15 // Whitespace from a sloppy paste.
16 {" https://x.11ch.at/join/Paul#e1.abc123\n", "https://x.11ch.at", "abc123", ""},
17 }
18 for _, c := range cases {
19 got, err := ParseInviteLink(c.link)
20 if err != nil {
21 t.Errorf("ParseInviteLink(%q): %v", c.link, err)
22 continue
23 }
24 if got.Base != c.base || got.T != c.tsec || got.Name != c.name {
25 t.Errorf("ParseInviteLink(%q) = %+v, want base=%q T=%q name=%q", c.link, got, c.base, c.tsec, c.name)
26 }
27 }
28
29 for _, bad := range []string{"", "not a link", "https://x.11ch.at/join/Paul", "https://x.11ch.at/join/Paul#e1."} {
30 if _, err := ParseInviteLink(bad); err == nil {
31 t.Errorf("ParseInviteLink(%q) should fail", bad)
32 }
33 }
34}
35