1 defmodule Pleroma.FormatterTest do
2 alias Pleroma.Formatter
8 test "turning urls into links" do
9 text = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla."
10 expected = "Hey, check out <a href='https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla'>https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a>."
12 assert Formatter.linkify(text) == expected
14 text = "https://mastodon.social/@lambadalambda"
15 expected = "<a href='https://mastodon.social/@lambadalambda'>https://mastodon.social/@lambadalambda</a>"
17 assert Formatter.linkify(text) == expected
19 text = "@lambadalambda"
20 expected = "@lambadalambda"
22 assert Formatter.linkify(text) == expected
24 text = "http://www.cs.vu.nl/~ast/intel/"
25 expected = "<a href='http://www.cs.vu.nl/~ast/intel/'>http://www.cs.vu.nl/~ast/intel/</a>"
27 assert Formatter.linkify(text) == expected
29 text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087"
30 expected = "<a href='https://forum.zdoom.org/viewtopic.php?f=44&t=57087'>https://forum.zdoom.org/viewtopic.php?f=44&t=57087</a>"
32 assert Formatter.linkify(text) == expected
34 text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul"
35 expected = "<a href='https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul'>https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>"
37 assert Formatter.linkify(text) == expected
41 describe ".parse_tags" do
42 test "parses tags in the text" do
43 text = "Here's a #Test. Maybe these are #working or not. What about #漢字? And #は。"
46 {"#working", "working"},
51 assert Formatter.parse_tags(text) == expected
55 test "it can parse mentions and return the relevant users" do
56 text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me"
58 gsimg = insert(:user, %{nickname: "gsimg"})
59 archaeme = insert(:user, %{nickname: "archaeme"})
60 archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
64 {"@archaeme", archaeme},
65 {"@archaeme@archae.me", archaeme_remote},
68 assert Formatter.parse_mentions(text) == expected_result
71 test "it adds cool emoji" do
72 text = "I love :moominmamma:"
74 expected_result = "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='/finmoji/128px/moominmamma-128.png' />"
76 assert Formatter.emojify(text) == expected_result
79 test "it returns the emoji used in the text" do
80 text = "I love :moominmamma:"
82 assert Formatter.get_emoji(text) == [{"moominmamma", "/finmoji/128px/moominmamma-128.png"}]