2019-06-24 10:56:27 +00:00
|
|
|
defmodule Linkify.BuilderTest do
|
2019-02-08 10:56:05 +00:00
|
|
|
use ExUnit.Case, async: true
|
2019-06-24 10:56:27 +00:00
|
|
|
doctest Linkify.Builder
|
2017-11-17 18:36:37 +00:00
|
|
|
|
2019-06-24 10:56:27 +00:00
|
|
|
import Linkify.Builder
|
2017-11-17 18:36:37 +00:00
|
|
|
|
2019-02-27 05:57:39 +00:00
|
|
|
test "create_link/2" do
|
2019-06-27 08:32:07 +00:00
|
|
|
expected = "<a href=\"http://text\">text</a>"
|
2019-02-27 05:57:39 +00:00
|
|
|
|
2019-02-27 17:33:06 +00:00
|
|
|
assert create_link("text", %{}) == expected
|
2019-02-27 05:57:39 +00:00
|
|
|
|
2019-06-27 08:32:07 +00:00
|
|
|
expected = "<a href=\"http://text\" target=\"_blank\">text</a>"
|
2019-02-27 05:57:39 +00:00
|
|
|
|
2019-06-27 08:32:07 +00:00
|
|
|
assert create_link("text", %{new_window: true}) == expected
|
|
|
|
|
|
|
|
expected = "<a href=\"http://text\" class=\"linkified\">text</a>"
|
|
|
|
assert create_link("text", %{class: "linkified"}) == expected
|
|
|
|
|
|
|
|
expected = "<a href=\"http://text\" rel=\"me\">text</a>"
|
2019-02-27 17:22:52 +00:00
|
|
|
|
2019-02-27 17:33:06 +00:00
|
|
|
assert create_link("text", %{rel: "me"}) == expected
|
2019-04-09 08:03:39 +00:00
|
|
|
|
2019-06-27 08:32:07 +00:00
|
|
|
expected = "<a href=\"http://text\">t...</a>"
|
2019-04-09 08:03:39 +00:00
|
|
|
|
2019-06-27 08:32:07 +00:00
|
|
|
assert create_link("text", %{truncate: 3}) == expected
|
2019-04-09 08:03:39 +00:00
|
|
|
|
2019-06-27 08:32:07 +00:00
|
|
|
expected = "<a href=\"http://text\">text</a>"
|
|
|
|
assert create_link("text", %{truncate: 2}) == expected
|
2019-04-09 08:03:39 +00:00
|
|
|
|
2019-06-27 08:32:07 +00:00
|
|
|
expected = "<a href=\"http://text\">http://text</a>"
|
|
|
|
assert create_link("http://text", %{strip_prefix: false}) == expected
|
2019-02-27 05:57:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "format_hashtag/3" do
|
|
|
|
expected = "<a href=\"/t/girls\">#girls</a>"
|
|
|
|
assert format_hashtag(%{href: "/t/girls"}, "girls", nil) == expected
|
|
|
|
end
|
|
|
|
|
|
|
|
test "format_email/3" do
|
|
|
|
expected = "<a href=\"mailto:user@example.org\">mailto:user@example.org</a>"
|
|
|
|
|
|
|
|
assert format_email(%{href: "mailto:user@example.org"}, "mailto:user@example.org", nil) ==
|
|
|
|
expected
|
|
|
|
end
|
|
|
|
|
|
|
|
test "format_mention/3" do
|
|
|
|
expected = "<a href=\"url\">@user@host</a>"
|
2019-03-01 21:49:56 +00:00
|
|
|
assert format_mention(%{href: "url"}, "user@host", nil) == expected
|
2019-02-27 05:57:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_mention_link/3" do
|
2019-06-27 08:32:07 +00:00
|
|
|
expected = "<a href=\"/u/navi\">@navi</a>"
|
2019-02-27 05:57:39 +00:00
|
|
|
|
|
|
|
assert create_mention_link("@navi", "hello @navi", %{mention_prefix: "/u/"}) == expected
|
|
|
|
end
|
|
|
|
|
|
|
|
test "create_email_link/3" do
|
2019-06-27 08:32:07 +00:00
|
|
|
expected = "<a href=\"mailto:user@example.org\">user@example.org</a>"
|
2019-02-27 05:57:39 +00:00
|
|
|
assert create_email_link("user@example.org", %{}) == expected
|
|
|
|
assert create_email_link("user@example.org", %{href: "mailto:user@example.org"}) == expected
|
|
|
|
end
|
2017-11-17 18:36:37 +00:00
|
|
|
end
|