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/ParseYamlHeaderTests.cs

128 lines
2.8 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
2022-09-06 05:53:22 +00:00
using MfGames.Gallium;
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 ParseYamlHeaderTests : NitrideTestBase
{
public ParseYamlHeaderTests(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>()
.GetTextContentString()
2022-07-09 04:52:10 +00:00
.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>()
.GetTextContentString()
2022-07-09 04:52:10 +00:00
.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>()
.GetTextContentString()
2022-07-09 04:52:10 +00:00
.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; }
}
}