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-nitride-cil/tests/MfGames.Nitride.Yaml.Tests/ParseYamlHeaderTest.cs

123 lines
2.6 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
2022-09-06 05:53:22 +00:00
using MfGames.Gallium;
2022-09-06 05:53:22 +00:00
using MfGames.Nitride.Contents;
using MfGames.Nitride.Tests;
using Xunit;
using Xunit.Abstractions;
2022-09-06 05:53:22 +00:00
namespace MfGames.Nitride.Yaml.Tests;
public class ParseYamlHeaderTest : NitrideTestBase
{
public ParseYamlHeaderTest(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public void ParseNoContent()
{
var input = new List<Entity>
{
new Entity().SetTextContent(new StringTextContent("---", "title: Test Title 1", "---"))
};
var op = new ParseYamlHeader<TestHeader>();
2022-07-09 04:52:10 +00:00
Entity output = input.Run(op)
.First();
Assert.True(output.Has<ITextContent>());
2022-07-09 04:52:10 +00:00
Assert.Equal(
new[]
{
string.Empty,
},
2022-07-09 04:52:10 +00:00
output.Get<ITextContent>()
.GetText()
.Split("\n"));
Assert.True(output.Has<TestHeader>());
2022-07-09 04:52:10 +00:00
Assert.Equal(
"Test Title 1",
output.Get<TestHeader>()
.Title);
}
[Fact]
public void ParseNoHeader()
{
var input = new List<Entity>
{
new Entity().SetTextContent(new StringTextContent("Hello"))
};
var op = new ParseYamlHeader<TestHeader>();
2022-07-09 04:52:10 +00:00
Entity output = input.Run(op)
.First();
Assert.True(output.Has<ITextContent>());
2022-07-09 04:52:10 +00:00
Assert.Equal(
new[]
{
"Hello",
string.Empty,
},
2022-07-09 04:52:10 +00:00
output.Get<ITextContent>()
.GetText()
.Split("\n"));
Assert.True(output.Has<TestHeader>());
2022-07-09 04:52:10 +00:00
Assert.Null(
output.Get<TestHeader>()
.Title);
}
[Fact]
public void ParseSimpleHeader()
{
var input = new List<Entity>
{
new Entity().SetTextContent(new StringTextContent("---", "title: Test Title 1", "---", "Hello"))
};
var op = new ParseYamlHeader<TestHeader>();
2022-07-09 04:52:10 +00:00
Entity output = input.Run(op)
.First();
Assert.True(output.Has<ITextContent>());
2022-07-09 04:52:10 +00:00
Assert.Equal(
new[]
{
"Hello",
string.Empty,
},
2022-07-09 04:52:10 +00:00
output.Get<ITextContent>()
.GetText()
.Split("\n"));
Assert.True(output.Has<TestHeader>());
2022-07-09 04:52:10 +00:00
Assert.Equal(
"Test Title 1",
output.Get<TestHeader>()
.Title);
}
private class TestHeader
{
public string? Title { get; set; }
}
}