2024-08-18 04:24:59 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
using MultiversalDiplomacy.Model;
|
|
|
|
using MultiversalDiplomacy.Script;
|
|
|
|
|
|
|
|
namespace MultiversalDiplomacyTests;
|
|
|
|
|
|
|
|
public class ScriptTests
|
|
|
|
{
|
|
|
|
static IEnumerable<TestCaseData> DatcTestCases()
|
|
|
|
{
|
|
|
|
foreach (var path in Directory.EnumerateFiles("Scripts/DATC"))
|
|
|
|
{
|
|
|
|
yield return new TestCaseData(path)
|
|
|
|
.SetName($"{{m}}({Path.GetFileNameWithoutExtension(path)})");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCaseSource(nameof(DatcTestCases))]
|
|
|
|
public void Test_DATC(string testScriptPath)
|
|
|
|
{
|
2024-08-25 03:17:46 +00:00
|
|
|
Assert.Ignore("Script tests postponed until parsing tests are done");
|
2024-08-18 20:32:36 +00:00
|
|
|
string filename = Path.GetFileName(testScriptPath);
|
|
|
|
int line = 0;
|
2024-09-03 03:20:59 +00:00
|
|
|
IScriptHandler handler = new SetupScriptHandler(
|
|
|
|
(msg) => {/* discard */},
|
2024-08-28 21:10:41 +00:00
|
|
|
World.WithStandardMap(),
|
2024-09-03 03:20:59 +00:00
|
|
|
Adjudicator.MovementPhase);
|
2024-08-18 04:24:59 +00:00
|
|
|
foreach (string input in File.ReadAllLines(testScriptPath)) {
|
2024-08-18 20:32:36 +00:00
|
|
|
line++;
|
2024-09-03 03:20:59 +00:00
|
|
|
var result = handler.HandleInput(input);
|
|
|
|
if (!result.Success) throw new AssertionException(
|
|
|
|
$"Script {filename} error at line {line}: {result.Message}");
|
|
|
|
if (result.NextHandler is null) throw new AssertionException(
|
|
|
|
$"Script {filename} quit unexpectedly at line {line}: \"{input}\"");
|
|
|
|
handler = result.NextHandler;
|
2024-08-18 04:24:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|