summaryrefslogtreecommitdiff
path: root/utils/utils_test.go
blob: ea41f48f6d5053fabe4f4f9a44871c16594f164f (plain)
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
package utils

import (
	"testing"
)

func TestUserAgent(t *testing.T) {
	testAgents := []string{
		"Pleroma 1.0.0-1168-ge18c7866-pleroma-dot-site; https://pleroma.site info@pleroma.site",
		"Mastodon 1.2.3 Bot",
		"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15 (Applebot/0.1; +http://www.apple.com/go/applebot)",
		"WhatsApp",
	}

	for _, agent := range testAgents {
		if !IsUserAgentABot(agent) {
			t.Error("Incorrect parsing of useragent", agent)
		}
	}
}

func TestGetHashtagsFromText(t *testing.T) {
	text := `Some text with a #hashtag goes here.\n\n
	Another #secondhashtag, goes here.\n\n
	#thirdhashtag`

	hashtags := GetHashtagsFromText(text)

	if hashtags[0] != "#hashtag" || hashtags[1] != "#secondhashtag" || hashtags[2] != "#thirdhashtag" {
		t.Error("Incorrect hashtags fetched from text.")
	}
}