using Markdig; using MfGames.Markdown.Extensions; using MfGames.TestSetup; using Xunit; using Xunit.Abstractions; namespace MfGames.Markdown.Tests; /// /// Tests the functionality of the WriteFiles(). /// public class WikiLinkTest : TestBase { public WikiLinkTest(ITestOutputHelper output) : base(output) { } [Fact] public void BareStringHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown.ToHtml( "This is text.", pipeline); Assert.Equal("

This is text.

\n", result); } [Fact] public void BlankStringHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown.ToHtml( "", pipeline); Assert.Equal("", result); } [Fact] public void LabeledWikiLinkHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown .ToHtml( "[[Test|Label]]", pipeline) .Replace("%5E", "^"); Assert.Equal("

Label

\n", result); } [Fact] public void PossessiveLabeledWikiLinkHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown .ToHtml( "[[Test|Label]]'s", pipeline) .Replace("%5E", "^"); Assert.Equal("

Label's

\n", result); } [Fact] public void PossessiveWikiLinkHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown .ToHtml( "[[Test]]'s", pipeline) .Replace("%5E", "^"); Assert.Equal("

Test's

\n", result); } [Fact] public void PunctuationLabeledWikiLinkHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown .ToHtml( "[[Test|Label]].", pipeline) .Replace("%5E", "^"); Assert.Equal("

Label.

\n", result); } [Fact] public void PunctuationWikiLinkHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown .ToHtml( "[[Test]].", pipeline) .Replace("%5E", "^"); Assert.Equal("

Test.

\n", result); } [Fact] public void SentenceWikiLinkHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown .ToHtml( "This is a [[test]] of this system.", pipeline) .Replace("%5E", "^"); Assert.Equal( "

This is a test of this system.

\n", result); } [Fact] public void SimpleWikiLinkHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown .ToHtml( "[[Test]]", pipeline) .Replace("%5E", "^"); Assert.Equal("

Test

\n", result); } [Fact] public void StandardLinkHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown.ToHtml( "[Test](https://test/)", pipeline); Assert.Equal("

Test

\n", result); } [Fact] public void TrailingLabeledWikiLinkHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown .ToHtml( "[[Test|Label]]s", pipeline) .Replace("%5E", "^"); Assert.Equal("

Labels

\n", result); } [Fact] public void TrailingWikiLinkHtml() { MarkdownPipeline pipeline = CreatePipeline(); string result = Markdig.Markdown .ToHtml( "[[Test]]s", pipeline) .Replace("%5E", "^"); Assert.Equal("

Tests

\n", result); } private static MarkdownPipeline CreatePipeline() { WikiLinkOptions options = new() { GetUrl = (title) => string.Format( "^{0}$", title.ToLowerInvariant().Replace(" ", "-")), }; MarkdownPipelineBuilder? builder = new MarkdownPipelineBuilder() .Use(new WikiLinkExtension(options)); MarkdownPipeline? pipeline = builder.Build(); return pipeline; } }