logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker git clone https://hacktivis.me/git/auto_linker.git
commit: a4184277d00085d5cfc52fc79f2c4c7adf6ef6fe
parent 94193ca5f97c1f9fdf3d1469653e2d46fac34bcd
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed, 27 Feb 2019 06:57:39 +0100

AutoLinker.BuilderTest: Put tests on all the public functions

Diffstat:

Mtest/builder_test.exs50++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+), 0 deletions(-)

diff --git a/test/builder_test.exs b/test/builder_test.exs @@ -4,6 +4,43 @@ defmodule AutoLinker.BuilderTest do import AutoLinker.Builder + test "create_link/2" do + expected = + "<a href=\"text\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">text</a>" + + assert create_link("text", %{href: "url"}) == expected + + expected = "<a href=\"text\" class=\"auto-linker\" target=\"_blank\">text</a>" + assert create_link("text", %{href: "url", rel: nil}) == expected + + expected = "<a href=\"text\" class=\"auto-linker\" target=\"_blank\" rel=\"me\">text</a>" + assert create_link("text", %{href: "url", rel: "me"}) == expected + end + + test "create_markdown_links/2" do + expected = + "<a href='url' class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">text</a>" + + assert create_markdown_links("[text](url)", %{}) == expected + 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>" + format_mention(%{href: "url"}, "user@host", nil) == expected + end + describe "create_phone_link" do test "finishes" do assert create_phone_link([], "", []) == "" @@ -28,4 +65,17 @@ defmodule AutoLinker.BuilderTest do assert create_phone_link([["555.555.5555", ""], ["(555) 888-8888"]], phrase, []) == expected end end + + test "create_mention_link/3" do + expected = + "<a href=\"/u/navi\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">@navi</a>" + + assert create_mention_link("@navi", "hello @navi", %{mention_prefix: "/u/"}) == expected + end + + test "create_email_link/3" do + expected = "<a href=\"mailto:user@example.org\" class=\"auto-linker\">user@example.org</a>" + assert create_email_link("user@example.org", %{}) == expected + assert create_email_link("user@example.org", %{href: "mailto:user@example.org"}) == expected + end end