80 lines
2.1 KiB
C#
80 lines
2.1 KiB
C#
using MfGames.TestSetup;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace MfGames.Markdown.Tests;
|
|
|
|
/// <summary>
|
|
/// Tests the functionality of RewriteLinkTransformer.
|
|
/// </summary>
|
|
public class RewriteLinkTransformerTests : TestBase<TestContext>
|
|
{
|
|
public RewriteLinkTransformerTests(ITestOutputHelper output)
|
|
: base(output) { }
|
|
|
|
[Fact]
|
|
public void ComplexExample()
|
|
{
|
|
string input = string.Join(
|
|
"\n",
|
|
"# A [Heading](/heading/index.md)",
|
|
"",
|
|
"That includes many [not-changing](https://example.org) examples",
|
|
"and ones that [will change](/gary/index.md).",
|
|
"",
|
|
"No one knows how this [won't change](/favicon.ico).",
|
|
""
|
|
);
|
|
|
|
string expected = string.Join(
|
|
"\n",
|
|
"# A [Heading](/heading/)",
|
|
"",
|
|
"That includes many [not-changing](https://example.org) examples",
|
|
"and ones that [will change](/gary/).",
|
|
"",
|
|
"",
|
|
"No one knows how this [won't change](/favicon.ico).",
|
|
""
|
|
);
|
|
|
|
RewriteLinkTransformer transformer =
|
|
new((link) => link.Url = link.Url?.Replace("/index.md", "/"));
|
|
|
|
string? output = transformer.Transform(input);
|
|
|
|
Assert.Equal(expected, output);
|
|
}
|
|
|
|
[Fact]
|
|
public void HandleLink()
|
|
{
|
|
const string Input = "[Link Title](/link/index.md)";
|
|
|
|
RewriteLinkTransformer transformer =
|
|
new((link) => link.Url = link.Url?.Replace("/index.md", "/"));
|
|
|
|
string? output = transformer.Transform(Input);
|
|
|
|
Assert.Equal("[Link Title](/link/)", output);
|
|
}
|
|
|
|
[Fact]
|
|
public void HandleNulls()
|
|
{
|
|
RewriteLinkTransformer transformer = new();
|
|
|
|
Assert.Null(transformer.Transform(null));
|
|
}
|
|
|
|
[Fact]
|
|
public void HandleText()
|
|
{
|
|
const string Input = "Content";
|
|
RewriteLinkTransformer transformer = new();
|
|
string? output = transformer.Transform(Input);
|
|
|
|
Assert.Equal("Content", output);
|
|
}
|
|
}
|