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/Nitride.Yaml.Tests/ParseYamlHeaderTests.cs
2021-12-06 00:55:57 -06:00

114 lines
3 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Gallium;
using Nitride.Contents;
using Nitride.Tests;
using Xunit;
using Xunit.Abstractions;
namespace Nitride.Yaml.Tests
{
public class ParseYamlHeaderTests : NitrideTestsBase
{
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>();
Entity output = input
.Run(op)
.First();
Assert.True(output.Has<ITextContent>());
Assert.Equal(
new[]
{
string.Empty,
},
output.Get<ITextContent>().GetText().Split("\n"));
Assert.True(output.Has<TestHeader>());
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>();
Entity output = input
.Run(op)
.First();
Assert.True(output.Has<ITextContent>());
Assert.Equal(
new[]
{
"Hello",
string.Empty,
},
output.Get<ITextContent>().GetText().Split("\n"));
Assert.True(output.Has<TestHeader>());
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>();
Entity output = input
.Run(op)
.First();
Assert.True(output.Has<ITextContent>());
Assert.Equal(
new[]
{
"Hello",
string.Empty,
},
output.Get<ITextContent>().GetText().Split("\n"));
Assert.True(output.Has<TestHeader>());
Assert.Equal("Test Title 1", output.Get<TestHeader>().Title);
}
private class TestHeader
{
public string? Title { get; set; }
}
}
}