From 43d2e8feeaa4c3e75a33b8d1e0c6e4bafda5d944 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 27 Aug 2023 13:19:42 +0100 Subject: [PATCH] test: add tests for MDLink --- X10D.Tests/src/Text/MarkdownTests.cs | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/X10D.Tests/src/Text/MarkdownTests.cs b/X10D.Tests/src/Text/MarkdownTests.cs index 46a70ad..28bc5eb 100644 --- a/X10D.Tests/src/Text/MarkdownTests.cs +++ b/X10D.Tests/src/Text/MarkdownTests.cs @@ -105,6 +105,46 @@ internal class MarkdownTests Assert.That("Hello, world!".MDItalic(true), Is.EqualTo("_Hello, world!_")); } + [Test] + public void MDLink_ShouldThrowArgumentNullException_GivenNullUrl() + { + Assert.Multiple(() => + { + Assert.Throws(() => "".MDLink((string)null!)); + Assert.Throws(() => "".MDLink((Uri)null!)); + Assert.Throws(() => ((Uri)null!).MDLink("Hello, world!")); + }); + } + + [Test] + public void MDLink_ShouldReturnUrlOnly_GivenNullOrEmptyLabel() + { + const string url = "https://example.com/"; + Assert.Multiple(() => + { + Assert.That(((string)null!).MDLink(url), Is.EqualTo(url)); + Assert.That(string.Empty.MDLink(url), Is.EqualTo(url)); + + Assert.That(new Uri(url).MDLink(null), Is.EqualTo(url)); + Assert.That(new Uri(url).MDLink(string.Empty), Is.EqualTo(url)); + }); + } + + [Test] + public void MDLink_ShouldReturnFormattedLink_GivenValidLabelAndUrl() + { + const string url = "https://example.com/"; + const string label = "Hello, world!"; + + Assert.Multiple(() => + { + Assert.That(label.MDLink(url), Is.EqualTo($"[{label}]({url})")); + Assert.That(label.MDLink(new Uri(url)), Is.EqualTo($"[{label}]({url})")); + + Assert.That(new Uri(url).MDLink(label), Is.EqualTo($"[{label}]({url})")); + }); + } + [Test] public void MDStrikeOut_ShouldThrowArgumentNullException_GivenNull() {