From ae5eb22010a5e3ab00ebc8c2515c5077686f50f9 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Thu, 5 Sep 2024 05:22:07 +0000 Subject: [PATCH] Implement support-hold parsing --- MultiversalDiplomacy/Model/OrderParser.cs | 17 +++++- MultiversalDiplomacyTests/ReplTest.cs | 69 ++++++++++------------- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/MultiversalDiplomacy/Model/OrderParser.cs b/MultiversalDiplomacy/Model/OrderParser.cs index 51de6b8..2dbfdac 100644 --- a/MultiversalDiplomacy/Model/OrderParser.cs +++ b/MultiversalDiplomacy/Model/OrderParser.cs @@ -214,7 +214,8 @@ public class OrderParser(World world) return true; } - public static bool TryParseOrder(World world, string power, string command, [NotNullWhen(true)] out Order? order) { + public static bool TryParseOrder(World world, string power, string command, [NotNullWhen(true)] out Order? order) + { order = null; OrderParser re = new(world); @@ -346,7 +347,19 @@ public class OrderParser(World world) { order = null; var support = ParseSupportHold(match); - throw new NotImplementedException(); + + if (!TryParseOrderSubject(world, support.timeline, support.turn, support.province, out Unit? subject)) { + return false; + } + + if (!TryParseOrderSubject( + world, support.targetTimeline, support.targetTurn, support.targetProvince, out Unit? target)) + { + return false; + } + + order = new SupportHoldOrder(power, subject, target); + return true; } public static bool TryParseSupportMoveOrder( diff --git a/MultiversalDiplomacyTests/ReplTest.cs b/MultiversalDiplomacyTests/ReplTest.cs index 45339c2..9f3adac 100644 --- a/MultiversalDiplomacyTests/ReplTest.cs +++ b/MultiversalDiplomacyTests/ReplTest.cs @@ -161,6 +161,36 @@ public class ReplTest repl.AssertFails("assert no-move Mun"); } + [Test] + public void AssertSupportHold() + { + var repl = StandardRepl(); + + repl.ExecuteAll(""" + unit Germany A Mun + unit Germany A Boh + unit Austria A Tyr + --- + Germany Mun s Boh + --- + """); + + // Support is given + repl.Execute("assert support-given Mun"); + repl.AssertFails("assert support-cut Mun"); + + repl.ExecuteAll(""" + --- + Germany Mun s Boh + Austria Tyr - Mun + --- + """); + + // Support is cut + repl.Execute("assert support-cut Mun"); + repl.AssertFails("assert support-given Mun"); + } + [Test] public void AssertDislodged() { @@ -183,45 +213,6 @@ public class ReplTest repl.AssertFails("assert holds Tyr"); } - [Test] - public void AssertMoves() - { - Assert.Ignore(); - var repl = StandardRepl(); - - repl.ExecuteAll(""" - unit Germany A Mun - --- - Germany Mun - Tyr - --- - """); - - // Assertion should pass for a move - repl.Execute("assert moves Mun"); - // Assertion should fail for a successful move - repl.AssertFails("assert no-move Mun"); - } - - [Test] - public void AssertRepelled() - { - Assert.Ignore(); - var repl = StandardRepl(); - - repl.ExecuteAll(""" - unit Germany A Mun - unit Austria A Tyr - --- - Germany Mun - Tyr - --- - """); - - // Assertion should pass for a repelled move - repl.Execute("assert no-move Mun"); - // Assertion should fail for no move - repl.AssertFails("assert moves Mun"); - } - [Test] public void AssertSupports() {