utils_test.go

 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
// This file contains small tests for various utility functions.
package main

import (
	"encoding/json"
	"testing"
)

func TestExtractMentions(t *testing.T) {
	mentions := ExtractMentions("This is a second test post in prep for supporting mentions @sarahjamielewis@mastodon.social - this might work?")
	if len(mentions) != 1 {
		t.Fatalf("failed to extract mention...")
	} else {
		t.Logf("%v\n", mentions[0])
	}
}

func TestContextSerialization(t *testing.T) {
	item := PostMetaWithContext{}
	item.Context = []ContextElement{
		{Simple: StringOrArray{"https://www.w3.org/ns/activitystreams"}},
		{Complex: map[string]string{"ostatus": "http://ostatus.org#", "atomUri": "ostatus:atomUri", "inReplyToAtomUri": "ostatus:inReplyToAtomUri", "conversation": "ostatus:conversation", "sensitive": "as:sensitive", "toot": "http://joinmastodon.org/ns#", "votersCount": "toot:votersCount"}},
	}
	if data, err := json.Marshal(item); err == nil {
		t.Logf("%s\n", string(data))
	} else {
		t.Fatalf("error %v\n", err)
	}
}