42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System.Text;
|
|
using InkBlot.ParseHierarchy;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
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 InMemoryFileReader((string, string)[] filesToContents) : IFileReader
|
|
{
|
|
public Stream GetContents(string filename)
|
|
{
|
|
return new MemoryStream(Encoding.UTF8.GetBytes(filesToContents.First(e => e.Item1 == filename).Item2));
|
|
}
|
|
}
|
|
|
|
internal static class Helpers
|
|
{
|
|
public static ILoggerFactory GetLoggerFactory()
|
|
{
|
|
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
|
|
return loggerFactory;
|
|
}
|
|
}
|
|
|
|
public class TestBase
|
|
{
|
|
protected static (Story, Diagnostic[]) ParseText(string inkInput)
|
|
{
|
|
// parse the story
|
|
var fileReader = new InMemoryFileReader([
|
|
("main.ink", inkInput)
|
|
]);
|
|
using var loggerFactory = Helpers.GetLoggerFactory();
|
|
var (story, diagnosticsEnumerable) = InkBlotParser.Parse(fileReader, loggerFactory, "main.ink");
|
|
var diagnostics = diagnosticsEnumerable.ToArray();
|
|
|
|
return (story, diagnostics);
|
|
}
|
|
} |