logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker git clone https://hacktivis.me/git/auto_linker.git
commit: 73945481190210fedb0c6f5df63bb77133f6ec83
parent 32a6e41cd06bb5d9cc3f0bc962a3b70e88420696
Author: Egor Kislitsyn <egor@kislitsyn.com>
Date:   Tue,  9 Apr 2019 15:03:39 +0700

test coverage 100%! 🎉

Diffstat:

Mtest/auto_linker_test.exs18++++++++++++++++++
Mtest/builder_test.exs14++++++++++++--
Mtest/parser_test.exs7++++++-
3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/test/auto_linker_test.exs b/test/auto_linker_test.exs @@ -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 diff --git a/test/builder_test.exs b/test/builder_test.exs @@ -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 diff --git a/test/parser_test.exs b/test/parser_test.exs @@ -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