mfgames-cil/tests/MfGames.Nitride.Markdown.Tests/RewriteLinkToIndexPathTests.cs
D. Moonfire 23a65c8674
All checks were successful
deploy / deploy (push) Successful in 41m4s
feat: added a Markdown transformer to convert links to index paths
2024-03-18 22:27:42 -05:00

104 lines
2.9 KiB
C#

using System.Collections.Generic;
using System.Linq;
using MfGames.Gallium;
using MfGames.Nitride.Contents;
using MfGames.TestSetup;
using Xunit;
using Xunit.Abstractions;
namespace MfGames.Nitride.Markdown.Tests;
/// <summary>
/// Tests the functionality of the RewriteLinkToIndexPath operation.
/// </summary>
public class RewriteLinkToIndexPathTests : TestBase<MarkdownTestContext>
{
/// <inheritdoc />
public RewriteLinkToIndexPathTests(ITestOutputHelper output)
: base(output) { }
[Fact]
public void NoRewriteSimpleIndexPhp()
{
using MarkdownTestContext context = this.CreateContext();
List<Entity> input =
new()
{
new Entity().Set(IsMarkdown.Instance).SetTextContent("[Link Title](/index.php)"),
};
var op = context.Resolve<RewriteLinkToIndexPath>();
IEnumerable<Entity> output = op.Run(input);
Entity first = output.First();
string content = first.GetTextContentString()!.Trim();
Assert.Equal("[Link Title](/index.php)", content);
}
[Fact]
public void RewritePeriodSlashRelativePath()
{
using MarkdownTestContext context = this.CreateContext();
List<Entity> input =
new()
{
new Entity()
.Set(IsMarkdown.Instance)
.SetTextContent("[Link Title](./bob/index.md)"),
};
var op = context.Resolve<RewriteLinkToIndexPath>();
IEnumerable<Entity> output = op.Run(input);
Entity first = output.First();
string content = first.GetTextContentString()!.Trim();
Assert.Equal("[Link Title](./bob/)", content);
}
[Fact]
public void RewriteRemoteIndex()
{
using MarkdownTestContext context = this.CreateContext();
List<Entity> input =
new()
{
new Entity()
.Set(IsMarkdown.Instance)
.SetTextContent("[Link Title](https://example.org/index.md)"),
};
var op = context.Resolve<RewriteLinkToIndexPath>();
IEnumerable<Entity> output = op.Run(input);
Entity first = output.First();
string content = first.GetTextContentString()!.Trim();
Assert.Equal("[Link Title](https://example.org/index.md)", content);
}
[Fact]
public void RewriteSimpleIndexMarkdown()
{
using MarkdownTestContext context = this.CreateContext();
List<Entity> input =
new()
{
new Entity().Set(IsMarkdown.Instance).SetTextContent("[Link Title](/index.md)"),
};
var op = context.Resolve<RewriteLinkToIndexPath>();
IEnumerable<Entity> output = op.Run(input);
Entity first = output.First();
string content = first.GetTextContentString()!.Trim();
Assert.Equal("[Link Title](/)", content);
}
}