This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-markdown-cil/tests/MfGames.Markdown.Tests/WikiLinkTests.cs

189 lines
4.7 KiB
C#
Raw Normal View History

using Markdig;
using MfGames.Markdown.Extensions;
using MfGames.TestSetup;
using Xunit;
using Xunit.Abstractions;
namespace MfGames.Markdown.Tests;
/// <summary>
/// Tests the functionality of the WriteFiles().
/// </summary>
public class WikiLinkTest : TestBase<TestContext>
{
public WikiLinkTest(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public void BareStringHtml()
{
MarkdownPipeline pipeline = CreatePipeline();
string result = Markdig.Markdown.ToHtml(
"This is text.",
pipeline);
Assert.Equal("<p>This is text.</p>\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("<p><a href=\"^test$\">Label</a></p>\n", result);
}
[Fact]
public void PossessiveLabeledWikiLinkHtml()
{
MarkdownPipeline pipeline = CreatePipeline();
string result = Markdig.Markdown
.ToHtml(
"[[Test|Label]]'s",
pipeline)
.Replace("%5E", "^");
Assert.Equal("<p><a href=\"^test$\">Label's</a></p>\n", result);
}
[Fact]
public void PossessiveWikiLinkHtml()
{
MarkdownPipeline pipeline = CreatePipeline();
string result = Markdig.Markdown
.ToHtml(
"[[Test]]'s",
pipeline)
.Replace("%5E", "^");
Assert.Equal("<p><a href=\"^test$\">Test's</a></p>\n", result);
}
[Fact]
public void PunctuationLabeledWikiLinkHtml()
{
MarkdownPipeline pipeline = CreatePipeline();
string result = Markdig.Markdown
.ToHtml(
"[[Test|Label]].",
pipeline)
.Replace("%5E", "^");
Assert.Equal("<p><a href=\"^test$\">Label</a>.</p>\n", result);
}
[Fact]
public void PunctuationWikiLinkHtml()
{
MarkdownPipeline pipeline = CreatePipeline();
string result = Markdig.Markdown
.ToHtml(
"[[Test]].",
pipeline)
.Replace("%5E", "^");
Assert.Equal("<p><a href=\"^test$\">Test</a>.</p>\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(
"<p>This is a <a href=\"^test$\">test</a> of this system.</p>\n",
result);
}
[Fact]
public void SimpleWikiLinkHtml()
{
MarkdownPipeline pipeline = CreatePipeline();
string result = Markdig.Markdown
.ToHtml(
"[[Test]]",
pipeline)
.Replace("%5E", "^");
Assert.Equal("<p><a href=\"^test$\">Test</a></p>\n", result);
}
[Fact]
public void StandardLinkHtml()
{
MarkdownPipeline pipeline = CreatePipeline();
string result = Markdig.Markdown.ToHtml(
"[Test](https://test/)",
pipeline);
Assert.Equal("<p><a href=\"https://test/\">Test</a></p>\n", result);
}
[Fact]
public void TrailingLabeledWikiLinkHtml()
{
MarkdownPipeline pipeline = CreatePipeline();
string result = Markdig.Markdown
.ToHtml(
"[[Test|Label]]s",
pipeline)
.Replace("%5E", "^");
Assert.Equal("<p><a href=\"^test$\">Labels</a></p>\n", result);
}
[Fact]
public void TrailingWikiLinkHtml()
{
MarkdownPipeline pipeline = CreatePipeline();
string result = Markdig.Markdown
.ToHtml(
"[[Test]]s",
pipeline)
.Replace("%5E", "^");
Assert.Equal("<p><a href=\"^test$\">Tests</a></p>\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;
}
}