155 lines
4.8 KiB
C#
155 lines
4.8 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 ParseMarkdownHeadingOne operation.
|
|
/// </summary>
|
|
public class ParseMarkdownHeadingOneTests : TestBase<MarkdownTestContext>
|
|
{
|
|
public ParseMarkdownHeadingOneTests(ITestOutputHelper output)
|
|
: base(output) { }
|
|
|
|
[Fact]
|
|
public void ParseComplexHeader()
|
|
{
|
|
using MarkdownTestContext context = this.CreateContext();
|
|
|
|
List<Entity> input =
|
|
new()
|
|
{
|
|
new Entity()
|
|
.Set(IsMarkdown.Instance)
|
|
.SetTextContent("# Heading [One](/test)\n\nContent\nsecond\n\nline"),
|
|
};
|
|
|
|
ParseMarkdownHeadingOne op = context
|
|
.Resolve<ParseMarkdownHeadingOne>()
|
|
.WithAddModelCallback((entity, heading) => entity.Set(heading));
|
|
|
|
IEnumerable<Entity> output = op.Run(input);
|
|
Entity first = output.First();
|
|
string content = first.GetTextContentString()!.Trim();
|
|
|
|
Assert.Equal("Content\nsecond\n\nline", content);
|
|
Assert.Equal("Heading [One](/test)", first.Get<string>());
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseEmptyHeader()
|
|
{
|
|
using MarkdownTestContext context = this.CreateContext();
|
|
|
|
List<Entity> input =
|
|
new() { new Entity().Set(IsMarkdown.Instance).SetTextContent("#\nContent"), };
|
|
|
|
ParseMarkdownHeadingOne op = context
|
|
.Resolve<ParseMarkdownHeadingOne>()
|
|
.WithAddModelCallback((entity, heading) => entity.Set(heading));
|
|
|
|
IEnumerable<Entity> output = op.Run(input);
|
|
Entity first = output.First();
|
|
string content = first.GetTextContentString()!.Trim();
|
|
|
|
Assert.Equal("Content", content);
|
|
Assert.Equal("", first.Get<string>());
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseHeaderTwo()
|
|
{
|
|
using MarkdownTestContext context = this.CreateContext();
|
|
|
|
List<Entity> input =
|
|
new()
|
|
{
|
|
new Entity().Set(IsMarkdown.Instance).SetTextContent("## Heading Two\nContent"),
|
|
};
|
|
|
|
ParseMarkdownHeadingOne op = context
|
|
.Resolve<ParseMarkdownHeadingOne>()
|
|
.WithAddModelCallback((entity, heading) => entity.Set(heading));
|
|
|
|
IEnumerable<Entity> output = op.Run(input);
|
|
Entity first = output.First();
|
|
string content = first.GetTextContentString()!.Trim();
|
|
|
|
Assert.Equal("## Heading Two\nContent", content);
|
|
Assert.False(first.Has<string>());
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseMultipleHeaderOne()
|
|
{
|
|
using MarkdownTestContext context = this.CreateContext();
|
|
|
|
List<Entity> input =
|
|
new()
|
|
{
|
|
new Entity()
|
|
.Set(IsMarkdown.Instance)
|
|
.SetTextContent("# Heading One\n\n# Heading Two\n Content"),
|
|
};
|
|
|
|
ParseMarkdownHeadingOne op = context
|
|
.Resolve<ParseMarkdownHeadingOne>()
|
|
.WithAddModelCallback((entity, heading) => entity.Set(heading));
|
|
|
|
IEnumerable<Entity> output = op.Run(input);
|
|
Entity first = output.First();
|
|
string content = first.GetTextContentString()!.Trim();
|
|
|
|
Assert.Equal("# Heading Two\n Content", content);
|
|
Assert.Equal("Heading One", first.Get<string>());
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseNoHeader()
|
|
{
|
|
using MarkdownTestContext context = this.CreateContext();
|
|
|
|
List<Entity> input =
|
|
new() { new Entity().Set(IsMarkdown.Instance).SetTextContent("Content"), };
|
|
|
|
ParseMarkdownHeadingOne op = context
|
|
.Resolve<ParseMarkdownHeadingOne>()
|
|
.WithAddModelCallback((entity, heading) => entity.Set(heading));
|
|
|
|
IEnumerable<Entity> output = op.Run(input);
|
|
Entity first = output.First();
|
|
string content = first.GetTextContentString()!.Trim();
|
|
|
|
Assert.Equal("Content", content);
|
|
Assert.False(first.Has<string>());
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseSimpleHeader()
|
|
{
|
|
using MarkdownTestContext context = this.CreateContext();
|
|
|
|
List<Entity> input =
|
|
new()
|
|
{
|
|
new Entity().Set(IsMarkdown.Instance).SetTextContent("# Heading One\n\nContent"),
|
|
};
|
|
|
|
ParseMarkdownHeadingOne op = context
|
|
.Resolve<ParseMarkdownHeadingOne>()
|
|
.WithAddModelCallback((entity, heading) => entity.Set(heading));
|
|
|
|
IEnumerable<Entity> output = op.Run(input);
|
|
Entity first = output.First();
|
|
string content = first.GetTextContentString()!.Trim();
|
|
|
|
Assert.Equal("Content", content);
|
|
Assert.Equal("Heading One", first.Get<string>());
|
|
}
|
|
}
|