logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker git clone https://hacktivis.me/git/auto_linker.git

builder_test.exs (2078B)


  1. defmodule Linkify.BuilderTest do
  2. use ExUnit.Case, async: true
  3. doctest Linkify.Builder
  4. import Linkify.Builder
  5. test "create_link/2" do
  6. expected = "<a href=\"http://text\">http://text</a>"
  7. assert create_link("http://text", %{}) == expected
  8. expected = "<a href=\"http://text\" target=\"_blank\">http://text</a>"
  9. assert create_link("http://text", %{new_window: true}) == expected
  10. expected = "<a href=\"http://text\" class=\"linkified\">http://text</a>"
  11. assert create_link("http://text", %{class: "linkified"}) == expected
  12. expected = "<a href=\"http://text\" rel=\"me\">http://text</a>"
  13. assert create_link("http://text", %{rel: "me"}) == expected
  14. expected = "<a href=\"http://text\">h...</a>"
  15. assert create_link("http://text", %{truncate: 3}) == expected
  16. expected = "<a href=\"http://text\">http://text</a>"
  17. assert create_link("http://text", %{truncate: 2}) == expected
  18. expected = "<a href=\"http://text\">http://text</a>"
  19. assert create_link("http://text", %{strip_prefix: false}) == expected
  20. end
  21. test "format_hashtag/3" do
  22. expected = "<a href=\"/t/girls\">#girls</a>"
  23. assert format_hashtag(%{href: "/t/girls"}, "girls", nil) == expected
  24. end
  25. test "format_email/3" do
  26. expected = "<a href=\"mailto:user@example.org\">mailto:user@example.org</a>"
  27. assert format_email(%{href: "mailto:user@example.org"}, "mailto:user@example.org", nil) ==
  28. expected
  29. end
  30. test "format_mention/3" do
  31. expected = "<a href=\"url\">@user@host</a>"
  32. assert format_mention(%{href: "url"}, "user@host", nil) == expected
  33. end
  34. test "create_mention_link/3" do
  35. expected = "<a href=\"/u/navi\">@navi</a>"
  36. assert create_mention_link("@navi", "hello @navi", %{mention_prefix: "/u/"}) == expected
  37. end
  38. test "create_email_link/3" do
  39. expected = "<a href=\"mailto:user@example.org\">user@example.org</a>"
  40. assert create_email_link("user@example.org", %{}) == expected
  41. assert create_email_link("user@example.org", %{href: "mailto:user@example.org"}) == expected
  42. end
  43. end