|
|
@ -1,15 +1,15 @@ |
|
|
|
defmodule AutoLinkerTest do |
|
|
|
defmodule LinkifyTest do |
|
|
|
use ExUnit.Case, async: true |
|
|
|
doctest AutoLinker |
|
|
|
doctest Linkify |
|
|
|
|
|
|
|
test "default link" do |
|
|
|
assert AutoLinker.link("google.com") == |
|
|
|
"<a href=\"http://google.com\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">google.com</a>" |
|
|
|
assert Linkify.link("google.com") == |
|
|
|
"<a href=\"http://google.com\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">google.com</a>" |
|
|
|
end |
|
|
|
|
|
|
|
test "does on link existing links" do |
|
|
|
text = ~s(<a href="http://google.com">google.com</a>) |
|
|
|
assert AutoLinker.link(text) == text |
|
|
|
assert Linkify.link(text) == text |
|
|
|
end |
|
|
|
|
|
|
|
test "all kinds of links" do |
|
|
@ -18,7 +18,7 @@ defmodule AutoLinkerTest do |
|
|
|
expected = |
|
|
|
"hello <a href=\"http://google.com\">google.com</a> <a href=\"https://ddg.com\">ddg.com</a> <a href=\"mailto:user@email.com\">user@email.com</a> <a href=\"irc:///mIRC\">irc:///mIRC</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, |
|
|
|
assert Linkify.link(text, |
|
|
|
email: true, |
|
|
|
extra: true, |
|
|
|
class: false, |
|
|
@ -36,7 +36,7 @@ defmodule AutoLinkerTest do |
|
|
|
url |> String.split(".") |> List.last() |
|
|
|
end |
|
|
|
|
|
|
|
assert AutoLinker.link(text, |
|
|
|
assert Linkify.link(text, |
|
|
|
class: false, |
|
|
|
new_window: false, |
|
|
|
rel: custom_rel |
|
|
@ -48,7 +48,7 @@ defmodule AutoLinkerTest do |
|
|
|
|
|
|
|
custom_rel = fn _ -> nil end |
|
|
|
|
|
|
|
assert AutoLinker.link(text, |
|
|
|
assert Linkify.link(text, |
|
|
|
class: false, |
|
|
|
new_window: false, |
|
|
|
rel: custom_rel |
|
|
@ -56,8 +56,8 @@ defmodule AutoLinkerTest do |
|
|
|
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>", |
|
|
|
assert Linkify.link_map("google.com", []) == |
|
|
|
{"<a href=\"http://google.com\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">google.com</a>", |
|
|
|
[]} |
|
|
|
end |
|
|
|
|
|
|
@ -76,7 +76,7 @@ defmodule AutoLinkerTest do |
|
|
|
end |
|
|
|
|
|
|
|
{result_text, %{mentions: mentions}} = |
|
|
|
AutoLinker.link_map(text, %{mentions: MapSet.new()}, |
|
|
|
Linkify.link_map(text, %{mentions: MapSet.new()}, |
|
|
|
mention: true, |
|
|
|
mention_handler: handler |
|
|
|
) |
|
|
@ -91,12 +91,12 @@ defmodule AutoLinkerTest do |
|
|
|
text = "#hello #world" |
|
|
|
|
|
|
|
handler = fn hashtag, buffer, opts, acc -> |
|
|
|
link = AutoLinker.Builder.create_hashtag_link(hashtag, buffer, opts) |
|
|
|
link = Linkify.Builder.create_hashtag_link(hashtag, buffer, opts) |
|
|
|
{link, %{acc | tags: MapSet.put(acc.tags, hashtag)}} |
|
|
|
end |
|
|
|
|
|
|
|
{result_text, %{tags: tags}} = |
|
|
|
AutoLinker.link_map(text, %{tags: MapSet.new()}, |
|
|
|
Linkify.link_map(text, %{tags: MapSet.new()}, |
|
|
|
hashtag: true, |
|
|
|
hashtag_handler: handler, |
|
|
|
hashtag_prefix: "https://example.com/user/", |
|
|
@ -120,9 +120,9 @@ defmodule AutoLinkerTest do |
|
|
|
end |
|
|
|
|
|
|
|
expected = |
|
|
|
~s(Hello again, <span class="h-card"><a href="#/user/user">@<span>@user</span></a></span>.<script></script>\nThis is on another :moominmamma: line. <a href="/tag/2hu" class="auto-linker" target="_blank" rel="noopener noreferrer">#2hu</a> <a href="/tag/epic" class="auto-linker" target="_blank" rel="noopener noreferrer">#epic</a> <a href="/tag/phantasmagoric" class="auto-linker" target="_blank" rel="noopener noreferrer">#phantasmagoric</a>) |
|
|
|
~s(Hello again, <span class="h-card"><a href="#/user/user">@<span>@user</span></a></span>.<script></script>\nThis is on another :moominmamma: line. <a href="/tag/2hu" class="linkified" target="_blank" rel="noopener noreferrer">#2hu</a> <a href="/tag/epic" class="linkified" target="_blank" rel="noopener noreferrer">#epic</a> <a href="/tag/phantasmagoric" class="linkified" target="_blank" rel="noopener noreferrer">#phantasmagoric</a>) |
|
|
|
|
|
|
|
assert AutoLinker.link(text, |
|
|
|
assert Linkify.link(text, |
|
|
|
mention: true, |
|
|
|
mention_handler: handler, |
|
|
|
hashtag: true, |
|
|
@ -134,9 +134,9 @@ defmodule AutoLinkerTest do |
|
|
|
describe "mentions" do |
|
|
|
test "simple mentions" do |
|
|
|
expected = |
|
|
|
~s{hello <a href="https://example.com/user/user" class="auto-linker" target="_blank" rel="noopener noreferrer">@user</a> and <a href="https://example.com/user/anotherUser" class="auto-linker" target="_blank" rel="noopener noreferrer">@anotherUser</a>.} |
|
|
|
~s{hello <a href="https://example.com/user/user" class="linkified" target="_blank" rel="noopener noreferrer">@user</a> and <a href="https://example.com/user/anotherUser" class="linkified" target="_blank" rel="noopener noreferrer">@anotherUser</a>.} |
|
|
|
|
|
|
|
assert AutoLinker.link("hello @user and @anotherUser.", |
|
|
|
assert Linkify.link("hello @user and @anotherUser.", |
|
|
|
mention: true, |
|
|
|
mention_prefix: "https://example.com/user/" |
|
|
|
) == expected |
|
|
@ -149,7 +149,7 @@ defmodule AutoLinkerTest do |
|
|
|
expected = |
|
|
|
"<p><strong>hello world</strong></p>\n<p><`em>another <a href=\"u/user__test\">@user__test</a> and <a href=\"u/user__test\">@user__test</a> <a href=\"http://google.com\">google.com</a> paragraph</em></p>\n" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, |
|
|
|
assert Linkify.link(text, |
|
|
|
mention: true, |
|
|
|
mention_prefix: "u/", |
|
|
|
class: false, |
|
|
@ -162,9 +162,9 @@ defmodule AutoLinkerTest do |
|
|
|
text = "hey @user@example.com" |
|
|
|
|
|
|
|
expected = |
|
|
|
"hey <a href=\"https://example.com/user/user@example.com\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">@user@example.com</a>" |
|
|
|
"hey <a href=\"https://example.com/user/user@example.com\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">@user@example.com</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, |
|
|
|
assert Linkify.link(text, |
|
|
|
mention: true, |
|
|
|
mention_prefix: "https://example.com/user/" |
|
|
|
) == expected |
|
|
@ -174,9 +174,9 @@ defmodule AutoLinkerTest do |
|
|
|
describe "hashtag links" do |
|
|
|
test "hashtag" do |
|
|
|
expected = |
|
|
|
" one <a href=\"https://example.com/tag/2two\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">#2two</a> three <a href=\"https://example.com/tag/four\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">#four</a>." |
|
|
|
" one <a href=\"https://example.com/tag/2two\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">#2two</a> three <a href=\"https://example.com/tag/four\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">#four</a>." |
|
|
|
|
|
|
|
assert AutoLinker.link(" one #2two three #four.", |
|
|
|
assert Linkify.link(" one #2two three #four.", |
|
|
|
hashtag: true, |
|
|
|
hashtag_prefix: "https://example.com/tag/" |
|
|
|
) == expected |
|
|
@ -185,7 +185,7 @@ defmodule AutoLinkerTest do |
|
|
|
test "must have non-numbers" do |
|
|
|
expected = "<a href=\"/t/1ok\">#1ok</a> #42 #7" |
|
|
|
|
|
|
|
assert AutoLinker.link("#1ok #42 #7", |
|
|
|
assert Linkify.link("#1ok #42 #7", |
|
|
|
hashtag: true, |
|
|
|
hashtag_prefix: "/t/", |
|
|
|
class: false, |
|
|
@ -200,7 +200,7 @@ defmodule AutoLinkerTest do |
|
|
|
expected = |
|
|
|
"<a href=\"/t/administrateur·rice·s\">#administrateur·rice·s</a> <a href=\"/t/ingénieur·e·s\">#ingénieur·e·s</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, |
|
|
|
assert Linkify.link(text, |
|
|
|
hashtag: true, |
|
|
|
hashtag_prefix: "/t/", |
|
|
|
class: false, |
|
|
@ -215,7 +215,7 @@ defmodule AutoLinkerTest do |
|
|
|
expected = |
|
|
|
"<a href=\"/t/చక్రం\">#చక్రం</a> <a href=\"/t/కకకకక్\">#కకకకక్</a> <a href=\"/t/కకకకాక\">#కకకకాక</a> <a href=\"/t/కకకక్రకకకక\">#కకకక్రకకకక</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, |
|
|
|
assert Linkify.link(text, |
|
|
|
hashtag: true, |
|
|
|
hashtag_prefix: "/t/", |
|
|
|
class: false, |
|
|
@ -230,7 +230,7 @@ defmodule AutoLinkerTest do |
|
|
|
expected = |
|
|
|
"<a href=\"http://google.com#test\">google.com#test</a> <a href=\"https://example.com/tag/test\">#test</a> <a href=\"http://google.com/#test\">google.com/#test</a> <a href=\"https://example.com/tag/tag\">#tag</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, |
|
|
|
assert Linkify.link(text, |
|
|
|
hashtag: true, |
|
|
|
class: false, |
|
|
|
new_window: false, |
|
|
@ -245,7 +245,7 @@ defmodule AutoLinkerTest do |
|
|
|
expected = |
|
|
|
"<a href=\"https://example.com/tag/漢字\">#漢字</a> <a href=\"https://example.com/tag/は\">#は</a> <a href=\"https://example.com/tag/тест\">#тест</a> <a href=\"https://example.com/tag/ทดสอบ\">#ทดสอบ</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, |
|
|
|
assert Linkify.link(text, |
|
|
|
class: false, |
|
|
|
new_window: false, |
|
|
|
rel: false, |
|
|
@ -260,75 +260,75 @@ defmodule AutoLinkerTest do |
|
|
|
text = "Hey, check out http://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla ." |
|
|
|
|
|
|
|
expected = |
|
|
|
"Hey, check out <a href=\"http://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a> ." |
|
|
|
"Hey, check out <a href=\"http://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a> ." |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
|
|
|
|
# no scheme |
|
|
|
text = "Hey, check out www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla ." |
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
end |
|
|
|
|
|
|
|
test "turn urls with schema into urls" do |
|
|
|
text = "📌https://google.com" |
|
|
|
expected = "📌<a href=\"https://google.com\">google.com</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, class: false, new_window: false, rel: false) == expected |
|
|
|
assert Linkify.link(text, class: false, new_window: false, rel: false) == expected |
|
|
|
end |
|
|
|
|
|
|
|
test "hostname/@user" do |
|
|
|
text = "https://example.com/@user" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"https://example.com/@user\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">example.com/@user</a>" |
|
|
|
"<a href=\"https://example.com/@user\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">example.com/@user</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
|
|
|
|
text = "https://example.com:4000/@user" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"https://example.com:4000/@user\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">example.com:4000/@user</a>" |
|
|
|
"<a href=\"https://example.com:4000/@user\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">example.com:4000/@user</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
|
|
|
|
text = "https://example.com:4000/@user" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"https://example.com:4000/@user\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">example.com:4000/@user</a>" |
|
|
|
"<a href=\"https://example.com:4000/@user\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">example.com:4000/@user</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
|
|
|
|
text = "@username" |
|
|
|
expected = "@username" |
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
|
|
|
|
text = "http://www.cs.vu.nl/~ast/intel/" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"http://www.cs.vu.nl/~ast/intel/\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">cs.vu.nl/~ast/intel/</a>" |
|
|
|
"<a href=\"http://www.cs.vu.nl/~ast/intel/\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">cs.vu.nl/~ast/intel/</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
|
|
|
|
text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"https://forum.zdoom.org/viewtopic.php?f=44&t=57087\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">forum.zdoom.org/viewtopic.php?f=44&t=57087</a>" |
|
|
|
"<a href=\"https://forum.zdoom.org/viewtopic.php?f=44&t=57087\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">forum.zdoom.org/viewtopic.php?f=44&t=57087</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
|
|
|
|
text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>" |
|
|
|
"<a href=\"https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
|
|
|
|
text = "https://en.wikipedia.org/wiki/Duff's_device" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"https://en.wikipedia.org/wiki/Duff's_device\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">en.wikipedia.org/wiki/Duff's_device</a>" |
|
|
|
"<a href=\"https://en.wikipedia.org/wiki/Duff's_device\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">en.wikipedia.org/wiki/Duff's_device</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
@ -336,16 +336,15 @@ defmodule AutoLinkerTest do |
|
|
|
test "xmpp" do |
|
|
|
text = "xmpp:user@example.com" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"xmpp:user@example.com\" class=\"auto-linker\">xmpp:user@example.com</a>" |
|
|
|
expected = "<a href=\"xmpp:user@example.com\" class=\"linkified\">xmpp:user@example.com</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, extra: true, new_window: false, rel: false) == expected |
|
|
|
assert Linkify.link(text, extra: true, new_window: false, rel: false) == expected |
|
|
|
end |
|
|
|
|
|
|
|
test "email" do |
|
|
|
text = "user@example.com" |
|
|
|
expected = "<a href=\"mailto:user@example.com\" class=\"auto-linker\">user@example.com</a>" |
|
|
|
assert AutoLinker.link(text, email: true) == expected |
|
|
|
expected = "<a href=\"mailto:user@example.com\" class=\"linkified\">user@example.com</a>" |
|
|
|
assert Linkify.link(text, email: true) == expected |
|
|
|
end |
|
|
|
|
|
|
|
test "magnet" do |
|
|
@ -353,9 +352,9 @@ defmodule AutoLinkerTest do |
|
|
|
"magnet:?xt=urn:btih:a4104a9d2f5615601c429fe8bab8177c47c05c84&dn=ubuntu-18.04.1.0-live-server-amd64.iso&tr=http%3A%2F%2Ftorrent.ubuntu.com%3A6969%2Fannounce&tr=http%3A%2F%2Fipv6.torrent.ubuntu.com%3A6969%2Fannounce" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"magnet:?xt=urn:btih:a4104a9d2f5615601c429fe8bab8177c47c05c84&dn=ubuntu-18.04.1.0-live-server-amd64.iso&tr=http%3A%2F%2Ftorrent.ubuntu.com%3A6969%2Fannounce&tr=http%3A%2F%2Fipv6.torrent.ubuntu.com%3A6969%2Fannounce\" class=\"auto-linker\">magnet:?xt=urn:btih:a4104a9d2f5615601c429fe8bab8177c47c05c84&dn=ubuntu-18.04.1.0-live-server-amd64.iso&tr=http%3A%2F%2Ftorrent.ubuntu.com%3A6969%2Fannounce&tr=http%3A%2F%2Fipv6.torrent.ubuntu.com%3A6969%2Fannounce</a>" |
|
|
|
"<a href=\"magnet:?xt=urn:btih:a4104a9d2f5615601c429fe8bab8177c47c05c84&dn=ubuntu-18.04.1.0-live-server-amd64.iso&tr=http%3A%2F%2Ftorrent.ubuntu.com%3A6969%2Fannounce&tr=http%3A%2F%2Fipv6.torrent.ubuntu.com%3A6969%2Fannounce\" class=\"linkified\">magnet:?xt=urn:btih:a4104a9d2f5615601c429fe8bab8177c47c05c84&dn=ubuntu-18.04.1.0-live-server-amd64.iso&tr=http%3A%2F%2Ftorrent.ubuntu.com%3A6969%2Fannounce&tr=http%3A%2F%2Fipv6.torrent.ubuntu.com%3A6969%2Fannounce</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, extra: true, new_window: false, rel: false) == expected |
|
|
|
assert Linkify.link(text, extra: true, new_window: false, rel: false) == expected |
|
|
|
end |
|
|
|
|
|
|
|
test "dweb" do |
|
|
@ -363,9 +362,9 @@ defmodule AutoLinkerTest do |
|
|
|
"dweb://584faa05d394190ab1a3f0240607f9bf2b7e2bd9968830a11cf77db0cea36a21+v1.0.0/path/to/file.txt" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"dweb://584faa05d394190ab1a3f0240607f9bf2b7e2bd9968830a11cf77db0cea36a21+v1.0.0/path/to/file.txt\" class=\"auto-linker\">dweb://584faa05d394190ab1a3f0240607f9bf2b7e2bd9968830a11cf77db0cea36a21+v1.0.0/path/to/file.txt</a>" |
|
|
|
"<a href=\"dweb://584faa05d394190ab1a3f0240607f9bf2b7e2bd9968830a11cf77db0cea36a21+v1.0.0/path/to/file.txt\" class=\"linkified\">dweb://584faa05d394190ab1a3f0240607f9bf2b7e2bd9968830a11cf77db0cea36a21+v1.0.0/path/to/file.txt</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text, extra: true, new_window: false, rel: false) == expected |
|
|
|
assert Linkify.link(text, extra: true, new_window: false, rel: false) == expected |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
@ -374,51 +373,51 @@ defmodule AutoLinkerTest do |
|
|
|
text = "https://google.com" |
|
|
|
|
|
|
|
expected = |
|
|
|
"<a href=\"https://google.com\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">google.com</a>" |
|
|
|
"<a href=\"https://google.com\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">google.com</a>" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
end |
|
|
|
|
|
|
|
test "only existing TLDs with scheme" do |
|
|
|
text = "this url https://google.foobar.blah11blah/ has invalid TLD" |
|
|
|
|
|
|
|
expected = "this url https://google.foobar.blah11blah/ has invalid TLD" |
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
|
|
|
|
text = "this url https://google.foobar.com/ has valid TLD" |
|
|
|
|
|
|
|
expected = |
|
|
|
"this url <a href=\"https://google.foobar.com/\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">google.foobar.com/</a> has valid TLD" |
|
|
|
"this url <a href=\"https://google.foobar.com/\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">google.foobar.com/</a> has valid TLD" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
end |
|
|
|
|
|
|
|
test "only existing TLDs without scheme" do |
|
|
|
text = "this url google.foobar.blah11blah/ has invalid TLD" |
|
|
|
assert AutoLinker.link(text) == text |
|
|
|
assert Linkify.link(text) == text |
|
|
|
|
|
|
|
text = "this url google.foobar.com/ has valid TLD" |
|
|
|
|
|
|
|
expected = |
|
|
|
"this url <a href=\"http://google.foobar.com/\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">google.foobar.com/</a> has valid TLD" |
|
|
|
"this url <a href=\"http://google.foobar.com/\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">google.foobar.com/</a> has valid TLD" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
end |
|
|
|
|
|
|
|
test "only existing TLDs with and without scheme" do |
|
|
|
text = "this url http://google.foobar.com/ has valid TLD" |
|
|
|
|
|
|
|
expected = |
|
|
|
"this url <a href=\"http://google.foobar.com/\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">google.foobar.com/</a> has valid TLD" |
|
|
|
"this url <a href=\"http://google.foobar.com/\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">google.foobar.com/</a> has valid TLD" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
|
|
|
|
text = "this url google.foobar.com/ has valid TLD" |
|
|
|
|
|
|
|
expected = |
|
|
|
"this url <a href=\"http://google.foobar.com/\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">google.foobar.com/</a> has valid TLD" |
|
|
|
"this url <a href=\"http://google.foobar.com/\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">google.foobar.com/</a> has valid TLD" |
|
|
|
|
|
|
|
assert AutoLinker.link(text) == expected |
|
|
|
assert Linkify.link(text) == expected |
|
|
|
end |
|
|
|
end |
|
|
|
end |