utils_test.go 885 B

1234567891011121314151617181920212223242526272829303132
  1. package utils
  2. import (
  3. "testing"
  4. )
  5. func TestUserAgent(t *testing.T) {
  6. testAgents := []string{
  7. "Pleroma 1.0.0-1168-ge18c7866-pleroma-dot-site; https://pleroma.site info@pleroma.site",
  8. "Mastodon 1.2.3 Bot",
  9. "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)",
  10. "WhatsApp",
  11. }
  12. for _, agent := range testAgents {
  13. if !IsUserAgentABot(agent) {
  14. t.Error("Incorrect parsing of useragent", agent)
  15. }
  16. }
  17. }
  18. func TestGetHashtagsFromText(t *testing.T) {
  19. text := `Some text with a #hashtag goes here.\n\n
  20. Another #secondhashtag, goes here.\n\n
  21. #thirdhashtag`
  22. hashtags := GetHashtagsFromText(text)
  23. if hashtags[0] != "#hashtag" || hashtags[1] != "#secondhashtag" || hashtags[2] != "#thirdhashtag" {
  24. t.Error("Incorrect hashtags fetched from text.")
  25. }
  26. }