5dplomacy/MultiversalDiplomacyTests/ReplTest.cs

90 lines
2.5 KiB
C#
Raw Normal View History

2024-08-27 04:18:36 +00:00
using NUnit.Framework;
using MultiversalDiplomacy.Model;
using MultiversalDiplomacy.Orders;
2024-08-27 04:18:36 +00:00
using MultiversalDiplomacy.Script;
namespace MultiversalDiplomacyTests;
public class ReplTest
{
2024-08-28 15:09:57 +00:00
private static ReplDriver StandardRepl() => new(
new SetupScriptHandler(World.WithStandardMap(), strict: true));
2024-08-27 04:18:36 +00:00
[Test]
public void SetupHandler()
{
2024-08-28 15:09:57 +00:00
var repl = StandardRepl();
2024-08-27 04:18:36 +00:00
repl["""
unit Germany A Munich
unit Austria Army Tyrolia
2024-08-28 00:45:38 +00:00
unit England F Lon
2024-08-28 15:01:27 +00:00
"""].AssertReady();
2024-08-27 04:18:36 +00:00
Assert.That(repl.Handler, Is.TypeOf<SetupScriptHandler>());
SetupScriptHandler handler = (SetupScriptHandler)repl.Handler!;
Assert.That(handler.World.Units.Count, Is.EqualTo(3));
Assert.That(handler.World.GetUnitAt("Mun"), Is.Not.Null);
Assert.That(handler.World.GetUnitAt("Tyr"), Is.Not.Null);
Assert.That(handler.World.GetUnitAt("Lon"), Is.Not.Null);
repl["""
---
2024-08-28 15:01:27 +00:00
"""].AssertReady();
2024-08-27 04:18:36 +00:00
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
}
[Test]
public void SubmitOrders()
{
2024-08-28 15:09:57 +00:00
var repl = StandardRepl();
repl["""
unit Germany A Mun
unit Austria A Tyr
unit England F Lon
2024-08-28 15:09:57 +00:00
---
Germany A Mun hold
Austria: Army Tyrolia - Vienna
England:
Lon h
2024-08-28 15:01:27 +00:00
"""].AssertReady();
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["""
---
2024-08-28 15:01:27 +00:00
"""].AssertReady();
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));
}
2024-08-28 15:01:27 +00:00
[Test]
public void AssertBasic()
{
2024-08-28 15:09:57 +00:00
var repl = StandardRepl();
repl["""
2024-08-28 15:01:27 +00:00
unit Germany A Munich
---
---
2024-08-28 15:09:57 +00:00
assert true
"""].AssertReady();
2024-08-28 15:01:27 +00:00
repl["assert false"].AssertClosed();
}
2024-08-27 04:18:36 +00:00
}