Add unit test for submitting orders in the repl

This commit is contained in:
Tim Van Baak 2024-08-28 00:46:32 +00:00
parent 43a2517a95
commit 44f2c25a2c
2 changed files with 44 additions and 2 deletions

View File

@ -16,7 +16,9 @@ public class GameScriptHandler(World world, bool strict = false) : IScriptHandle
/// </summary> /// </summary>
public bool Strict { get; } = strict; public bool Strict { get; } = strict;
private string? CurrentPower = null; private string? CurrentPower { get; set; } = null;
public List<Order> Orders { get; } = [];
public IScriptHandler? HandleInput(string input) public IScriptHandler? HandleInput(string input)
{ {
@ -70,7 +72,8 @@ public class GameScriptHandler(World world, bool strict = false) : IScriptHandle
} }
if (OrderParser.TryParseOrder(World, orderPower, orderText, out Order? order)) { if (OrderParser.TryParseOrder(World, orderPower, orderText, out Order? order)) {
Console.WriteLine($"Parsed {orderPower} order \"{orderText}\" but doing anything with it isn't implemented yet"); Console.WriteLine($"Parsed {orderPower} order: {order}");
Orders.Add(order);
return this; return this;
} }

View File

@ -1,6 +1,7 @@
using NUnit.Framework; using NUnit.Framework;
using MultiversalDiplomacy.Model; using MultiversalDiplomacy.Model;
using MultiversalDiplomacy.Orders;
using MultiversalDiplomacy.Script; using MultiversalDiplomacy.Script;
namespace MultiversalDiplomacyTests; namespace MultiversalDiplomacyTests;
@ -32,4 +33,42 @@ public class ReplTest
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>()); Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
} }
[Test]
public void SubmitOrders()
{
SetupScriptHandler setup = new(World.WithStandardMap(), strict: true);
ReplDriver repl = new ReplDriver(setup)["""
unit Germany A Mun
unit Austria A Tyr
unit England F Lon
begin
"""];
repl["""
Germany A Mun hold
Austria: Army Tyrolia - Vienna
England:
Lon h
"""].Ready();
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
GameScriptHandler handler = (GameScriptHandler)repl.Handler!;
Assert.That(handler.Orders.Count, Is.EqualTo(3));
Assert.That(handler.Orders.Single(o => o.Power == "Germany"), Is.TypeOf<HoldOrder>());
Assert.That(handler.Orders.Single(o => o.Power == "Austria"), Is.TypeOf<MoveOrder>());
Assert.That(handler.Orders.Single(o => o.Power == "England"), Is.TypeOf<HoldOrder>());
Assert.That(handler.World.Timelines.Pasts.Count, Is.EqualTo(1));
World before = handler.World;
repl["""
---
"""].Ready();
Assert.That(repl.Handler, Is.TypeOf<AdjudicationQueryScriptHandler>());
var newHandler = (AdjudicationQueryScriptHandler)repl.Handler!;
Assert.That(newHandler.World, Is.Not.EqualTo(before));
Assert.That(newHandler.World.Timelines.Pasts.Count, Is.EqualTo(2));
}
} }