Commit 73945481 authored by minibikini's avatar minibikini

test coverage 100%! 馃帀

parent 32a6e41c
......@@ -61,6 +61,24 @@ defmodule AutoLinkerTest do
new_window: false,
rel: custom_rel
) == expected
text = "google.com"
expected = "<a href=\"http://google.com\">google.com</a>"
custom_rel = fn _ -> nil end
assert AutoLinker.link(text,
class: false,
new_window: false,
rel: custom_rel
) == expected
end
test "link_map/2" do
assert AutoLinker.link_map("google.com", []) ==
{"<a href=\"http://google.com\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">google.com</a>",
[]}
end
describe "custom handlers" do
......
......@@ -17,6 +17,16 @@ defmodule AutoLinker.BuilderTest do
"<a href=\"http://text\" class=\"auto-linker\" target=\"_blank\" rel=\"me\">text</a>"
assert create_link("text", %{rel: "me"}) == expected
expected = "<a href=\"http://text\" class=\"auto-linker\" target=\"_blank\">t...</a>"
assert create_link("text", %{truncate: 3, rel: false}) == expected
expected = "<a href=\"http://text\" class=\"auto-linker\" target=\"_blank\">text</a>"
assert create_link("text", %{truncate: 2, rel: false}) == expected
expected = "<a href=\"http://text\" class=\"auto-linker\" target=\"_blank\">http://text</a>"
assert create_link("http://text", %{rel: false, strip_prefix: false}) == expected
end
test "create_markdown_links/2" do
......@@ -52,9 +62,9 @@ defmodule AutoLinker.BuilderTest do
phrase = "my exten is x888. Call me."
expected =
~s'my exten is <a href="#" class="phone-number" data-phone="888">x888</a>. Call me.'
~s'my exten is <a href="#" class="phone-number" data-phone="888" test=\"test\">x888</a>. Call me.'
assert create_phone_link([["x888", ""]], phrase, []) == expected
assert create_phone_link([["x888", ""]], phrase, attributes: [test: "test"]) == expected
end
test "handles multiple links" do
......
......@@ -85,7 +85,7 @@ defmodule AutoLinker.ParserTest do
expected = "<div><a href=\"http://google.com\">google.com</a></div>"
assert parse(text, class: false, rel: false, new_window: false) == expected
assert parse(text, class: false, rel: false, new_window: false, phone: false) == expected
text = "Check out <div class='section'>google.com</div>"
......@@ -105,6 +105,11 @@ defmodule AutoLinker.ParserTest do
text = "```Check out <div class='section'>google.com</div>```"
assert parse(text, exclude_patterns: ["```"]) == text
end
test "do not link urls" do
text = "google.com"
assert parse(text, url: false, phone: true) == text
end
end
def valid_number?([list], number) do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment