Something went wrong. Try again.
A Gemini Protocol capsule for viewing Bluesky, Standard Site & similar records from the Atmosphere
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051package render
import ( "testing"
"tangled.org/byjp.me/deepsky/internal/bsky")
func TestLinkLabel(t *testing.T) { cases := []struct { name string text string uri string want string }{ {"shortened url anchor", "sts2.byjp.me/did:plc:ephk...", "https://sts2.byjp.me/did:plc:ephkzpinhaqcabtkugtbzrwu", "Link from post"}, {"exact url anchor", "https://example.com/", "https://example.com/", "Link from post"}, {"bare domain anchor for deep link", "example.com", "https://example.com/some/path", "Link from post"}, {"www stripped", "www.example.com", "https://example.com", "Link from post"}, {"empty anchor", "", "https://example.com", "Link from post"}, {"worded label", "my cool site", "https://example.com", "my cool site"}, {"title that is not the url", "The Verge", "https://theverge.com/123", "The Verge"}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { got := linkLabel(bsky.Link{URI: c.uri, Text: c.text}) if got != c.want { t.Errorf("linkLabel(%q, %q) = %q, want %q", c.text, c.uri, got, c.want) } }) }}
func TestRecordLinksCoversText(t *testing.T) { // "see foo" where "foo" (bytes 4-7) links out. rec := bsky.PostRecord{ Text: "see foo", Facets: []bsky.Facet{{ Index: bsky.FacetIndex{ByteStart: 4, ByteEnd: 7}, Features: []bsky.FacetFeature{{Type: "app.bsky.richtext.facet#link", URI: "https://example.com"}}, }}, } links := rec.Links() if len(links) != 1 { t.Fatalf("got %d links, want 1", len(links)) } if links[0].Text != "foo" || links[0].URI != "https://example.com" { t.Errorf("got %+v", links[0]) }}