From a4184277d00085d5cfc52fc79f2c4c7adf6ef6fe Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 27 Feb 2019 06:57:39 +0100 Subject: [PATCH 1/4] AutoLinker.BuilderTest: Put tests on all the public functions --- test/builder_test.exs | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/builder_test.exs b/test/builder_test.exs index 4272359..8722acd 100644 --- a/test/builder_test.exs +++ b/test/builder_test.exs @@ -4,6 +4,43 @@ defmodule AutoLinker.BuilderTest do import AutoLinker.Builder + test "create_link/2" do + expected = + "text" + + assert create_link("text", %{href: "url"}) == expected + + expected = "text" + assert create_link("text", %{href: "url", rel: nil}) == expected + + expected = "text" + assert create_link("text", %{href: "url", rel: "me"}) == expected + end + + test "create_markdown_links/2" do + expected = + "text" + + assert create_markdown_links("[text](url)", %{}) == 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" + format_mention(%{href: "url"}, "user@host", nil) == expected + end + describe "create_phone_link" do test "finishes" do assert create_phone_link([], "", []) == "" @@ -28,4 +65,17 @@ defmodule AutoLinker.BuilderTest do 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 From 204ad610e3a14414d3b4543f6b4693f961213981 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 27 Feb 2019 18:22:52 +0100 Subject: [PATCH 2/4] AutoLinker.BuilderTest: Match (strange) behaviour --- test/builder_test.exs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/builder_test.exs b/test/builder_test.exs index 8722acd..90bd455 100644 --- a/test/builder_test.exs +++ b/test/builder_test.exs @@ -6,14 +6,16 @@ defmodule AutoLinker.BuilderTest do test "create_link/2" do expected = - "text" + "text" assert create_link("text", %{href: "url"}) == expected - expected = "text" + expected = "text" assert create_link("text", %{href: "url", rel: nil}) == expected - expected = "text" + expected = + "text" + assert create_link("text", %{href: "url", rel: "me"}) == expected end From bdd98ee731c49fe13d5e143bc2517a542aabc308 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 27 Feb 2019 18:33:06 +0100 Subject: [PATCH 3/4] AutoLinker.BuilderTest: Do not pass overridden href to create_link/2 --- test/builder_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/builder_test.exs b/test/builder_test.exs index 90bd455..779c5b2 100644 --- a/test/builder_test.exs +++ b/test/builder_test.exs @@ -8,15 +8,15 @@ defmodule AutoLinker.BuilderTest do expected = "text" - assert create_link("text", %{href: "url"}) == expected + assert create_link("text", %{}) == expected expected = "text" - assert create_link("text", %{href: "url", rel: nil}) == expected + assert create_link("text", %{rel: nil}) == expected expected = "text" - assert create_link("text", %{href: "url", rel: "me"}) == expected + assert create_link("text", %{rel: "me"}) == expected end test "create_markdown_links/2" do From 4dae1eadd5c31ecdb7874b145cf380808a971127 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 1 Mar 2019 22:49:56 +0100 Subject: [PATCH 4/4] AutoLinker.BuilderTest: Add forgotten assert on format_mention/3 --- test/builder_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/builder_test.exs b/test/builder_test.exs index 779c5b2..0742bd6 100644 --- a/test/builder_test.exs +++ b/test/builder_test.exs @@ -40,7 +40,7 @@ defmodule AutoLinker.BuilderTest do test "format_mention/3" do expected = "@user@host" - format_mention(%{href: "url"}, "user@host", nil) == expected + assert format_mention(%{href: "url"}, "user@host", nil) == expected end describe "create_phone_link" do