test coverage 100%! 🎉

This commit is contained in:
Egor Kislitsyn 2019-04-09 15:03:39 +07:00
parent 32a6e41cd0
commit 7394548119
3 changed files with 36 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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