defmodule AutoLinker.BuilderTest do
use ExUnit.Case, async: true
doctest AutoLinker.Builder
import AutoLinker.Builder
test "create_link/2" do
expected =
"text"
assert create_link("text", %{}) == expected
expected = "text"
assert create_link("text", %{rel: nil}) == expected
expected =
"text"
assert create_link("text", %{rel: "me"}) == expected
expected = "t..."
assert create_link("text", %{truncate: 3, rel: false}) == expected
expected = "text"
assert create_link("text", %{truncate: 2, rel: false}) == expected
expected = "http://text"
assert create_link("http://text", %{rel: false, strip_prefix: false}) == expected
end
test "format_hashtag/3" do
expected = "#girls"
assert format_hashtag(%{href: "/t/girls"}, "girls", nil) == expected
end
test "format_email/3" do
expected = "mailto:user@example.org"
assert format_email(%{href: "mailto:user@example.org"}, "mailto:user@example.org", nil) ==
expected
end
test "format_mention/3" do
expected = "@user@host"
assert format_mention(%{href: "url"}, "user@host", nil) == expected
end
describe "create_phone_link" do
test "finishes" do
assert create_phone_link([], "", []) == ""
end
test "handles one link" do
phrase = "my exten is x888. Call me."
expected =
~s'my exten is x888. Call me.'
assert create_phone_link([["x888", ""]], phrase, attributes: [test: "test"]) == expected
end
test "handles multiple links" do
phrase = "555.555.5555 or (555) 888-8888"
expected =
~s'555.555.5555 or ' <>
~s'(555) 888-8888'
assert create_phone_link([["555.555.5555", ""], ["(555) 888-8888"]], phrase, []) == expected
end
end
test "create_mention_link/3" do
expected =
"@navi"
assert create_mention_link("@navi", "hello @navi", %{mention_prefix: "/u/"}) == expected
end
test "create_email_link/3" do
expected = "user@example.org"
assert create_email_link("user@example.org", %{}) == expected
assert create_email_link("user@example.org", %{href: "mailto:user@example.org"}) == expected
end
end