feat: parse content text (base case).
This commit is contained in:
34
InkBlot.Tests/ContentTextTest.cs
Normal file
34
InkBlot.Tests/ContentTextTest.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using InkBlot.ParseHierarchy;
|
||||
using Shouldly;
|
||||
|
||||
namespace InkBlot.Tests;
|
||||
|
||||
public class ContentTextTest
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Hello!", "Hello!", 0)]
|
||||
[InlineData("Hel-lo!", "Hel-lo!", 0)]
|
||||
[InlineData("Hel\\lo!", "Hello!", 0)]
|
||||
[InlineData("Hel<lo!", "Hel<lo!", 0)]
|
||||
// TODO: check error situations better when diverts (->), threads (<-) and tags (#) are supported
|
||||
[InlineData("Hel->lo!", "", 1)]
|
||||
[InlineData("Hel<-lo!", "", 1)]
|
||||
[InlineData("Hel#lo!", "", 1)]
|
||||
public void TestBaseContentSuccess(string inkInput, string result, int numErrors)
|
||||
{
|
||||
// parse the story
|
||||
var fileReader = new PreMadeFileReader([
|
||||
("main.ink", inkInput)
|
||||
]);
|
||||
var parser = new InkBlotParser();
|
||||
var (story, diagnostics) = parser.Parse(fileReader, "main.ink");
|
||||
|
||||
// check the diagnostic counts match
|
||||
diagnostics.Count().ShouldBe(numErrors);
|
||||
|
||||
// check the contents match (only if there was no diagnostic)
|
||||
if (numErrors != 0) return;
|
||||
var contents = story.StoryNodes.ToArray();
|
||||
contents.ShouldBe([new Content(result)]);
|
||||
}
|
||||
}
|
||||
15
InkBlot.Tests/Helpers.cs
Normal file
15
InkBlot.Tests/Helpers.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Text;
|
||||
|
||||
namespace InkBlot.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// A file reader where the contents are directly provided as strings.
|
||||
/// </summary>
|
||||
/// <param name="filesToContents">A map between file names and their contents.</param>
|
||||
internal class PreMadeFileReader((string, string)[] filesToContents) : IFileReader
|
||||
{
|
||||
public Stream GetContents(string filename)
|
||||
{
|
||||
return new MemoryStream(Encoding.UTF8.GetBytes(filesToContents.First(e => e.Item1 == filename).Item2));
|
||||
}
|
||||
}
|
||||
26
InkBlot.Tests/InkBlot.Tests.csproj
Normal file
26
InkBlot.Tests/InkBlot.Tests.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
|
||||
<PackageReference Include="Shouldly" Version="4.3.0"/>
|
||||
<PackageReference Include="xunit" Version="2.9.2"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\InkBlot\InkBlot.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user