@@ -271,6 +271,70 @@ func TestAddImageFromBytes(t *testing.T) {
271271 }
272272}
273273
274+ func TestParseLinks (t * testing.T ) {
275+ content := "Hello https://go.dev and https://pkg.go.dev!"
276+ pb := NewPostBuilder (content )
277+ pb .parseLinks ()
278+ if len (pb .facets ) != 2 {
279+ t .Errorf ("wanted 2 facets, got %d" , len (pb .facets ))
280+ }
281+ if pb .facets [0 ].Index .ByteStart != 6 || pb .facets [0 ].Index .ByteEnd != 20 {
282+ t .Errorf ("wanted first facet index [6,20], got [%d,%d]" , pb .facets [0 ].Index .ByteStart , pb .facets [0 ].Index .ByteEnd )
283+ }
284+ if pb .facets [0 ].Features [0 ].Uri != "https://go.dev" {
285+ t .Errorf ("wanted first facet URI 'https://go.dev', got '%s'" , pb .facets [0 ].Features [0 ].Uri )
286+ }
287+ if pb .facets [1 ].Index .ByteStart != 25 || pb .facets [1 ].Index .ByteEnd != 43 {
288+ t .Errorf ("wanted second facet index [25,43], got [%d,%d]" , pb .facets [1 ].Index .ByteStart , pb .facets [1 ].Index .ByteEnd )
289+ }
290+ if pb .facets [1 ].Features [0 ].Uri != "https://pkg.go.dev" {
291+ t .Errorf ("wanted second facet URI 'https://pkg.go.dev', got '%s'" , pb .facets [1 ].Features [0 ].Uri )
292+ }
293+ }
294+
295+ func TestParseMentions (t * testing.T ) {
296+ // TODO: Implement a mock server response for identity resolution to fully test this.
297+ // content := "Hello @itodd.dev and @golang.org!"
298+ // pb := NewPostBuilder(content)
299+ // pb.parseMentions()
300+ // if len(pb.facets) != 2 {
301+ // t.Errorf("wanted 2 facets, got %d", len(pb.facets))
302+ // }
303+ // if pb.facets[0].Index.ByteStart != 6 || pb.facets[0].Index.ByteEnd != 16 {
304+ // t.Errorf("wanted first facet index [6,16], got [%d,%d]", pb.facets[0].Index.ByteStart, pb.facets[0].Index.ByteEnd)
305+ // }
306+ // if pb.facets[0].Features[0].Did != "did:example:itodd" {
307+ // t.Errorf("wanted first facet DID 'did:example:itodd', got '%s'", pb.facets[0].Features[0].Did)
308+ // }
309+ // if pb.facets[1].Index.ByteStart != 21 || pb.facets[1].Index.ByteEnd != 33 {
310+ // t.Errorf("wanted second facet index [21,33], got [%d,%d]", pb.facets[1].Index.ByteStart, pb.facets[1].Index.ByteEnd)
311+ // }
312+ // if pb.facets[1].Features[0].Did != "did:example:golang" {
313+ // t.Errorf("wanted second facet DID 'did:example:golang', got '%s'", pb.facets[1].Features[0].Did)
314+ // }
315+ }
316+
317+ func TestParseTags (t * testing.T ) {
318+ content := "This is a test post with #golang and #bsky tags."
319+ pb := NewPostBuilder (content )
320+ pb .parseTags ()
321+ if len (pb .facets ) != 2 {
322+ t .Errorf ("wanted 2 facets, got %d" , len (pb .facets ))
323+ }
324+ if pb .facets [0 ].Index .ByteStart != 25 || pb .facets [0 ].Index .ByteEnd != 32 {
325+ t .Errorf ("wanted first facet index [25,32], got [%d,%d]" , pb .facets [0 ].Index .ByteStart , pb .facets [0 ].Index .ByteEnd )
326+ }
327+ if pb .facets [0 ].Features [0 ].Tag != "golang" {
328+ t .Errorf ("wanted first facet text 'golang', got '%s'" , pb .facets [0 ].Features [0 ].Tag )
329+ }
330+ if pb .facets [1 ].Index .ByteStart != 37 || pb .facets [1 ].Index .ByteEnd != 42 {
331+ t .Errorf ("wanted second facet index [37,42], got [%d,%d]" , pb .facets [1 ].Index .ByteStart , pb .facets [1 ].Index .ByteEnd )
332+ }
333+ if pb .facets [1 ].Features [0 ].Tag != "bsky" {
334+ t .Errorf ("wanted second facet text 'bsky', got '%s'" , pb .facets [1 ].Features [0 ].Tag )
335+ }
336+ }
337+
274338func newMockServer () * httptest.Server {
275339 return httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
276340 switch r .URL .Path {
0 commit comments