1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package logic
import (
"regexp"
"testing"
)
// getUrl gets a note's content as Mastodon sends it: HTML, a mention of the
// birb and the URL of the feed to follow, each in a link.
func TestGetUrl(t *testing.T) {
ib := &inbox{reHttps: regexp.MustCompile(`https?://\S+`)}
mention := `<span class="h-card"><a href="https://birb.example/u/birb" class="u-url mention">@<span>birb</span></a></span> `
for _, c := range []struct {
name, content, want string
}{
{"ampersand in query",
`<p>` + mention + `<a href="https://ex.com/f?a=1&b=2">https://ex.com/f?a=1&b=2</a></p>`,
"https://ex.com/f?a=1&b=2"},
{"next paragraph",
`<p>` + mention + `<a href="https://ex.com/blog">https://ex.com/blog</a></p><p>thanks!</p>`,
"https://ex.com/blog"},
{"line break",
`<p>` + mention + `<a href="https://ex.com/blog">https://ex.com/blog</a><br>thanks</p>`,
"https://ex.com/blog"},
{"shortened link",
`<p>` + mention + `<a href="https://ex.com/long"><span class="invisible">https://</span><span class="ellipsis">ex.com/lo</span><span class="invisible">ng</span></a></p>`,
"https://ex.com/long"},
{"two urls",
`<p>` + mention + `<a href="https://ex.com/a">https://ex.com/a</a></p><p><a href="https://ex.com/b">https://ex.com/b</a></p>`,
""},
} {
t.Run(c.name, func(t *testing.T) {
if got := ib.getUrl(c.content); got != c.want {
t.Errorf("getUrl = %q, want %q", got, c.want)
}
})
}
}
|