diff --git a/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs b/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs index 683089b..32f63aa 100644 --- a/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs +++ b/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs @@ -35,7 +35,8 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) : break; case "assert": - return HandleAssertion(args[1]); + if (!EvaluateAssertion(args[1])) return Strict ? null : this; + break; case "status": throw new NotImplementedException(); @@ -49,19 +50,48 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) : return this; } - private AdjudicationQueryScriptHandler? HandleAssertion(string assertion) + private bool EvaluateAssertion(string assertion) { - // Simple assertions - switch (assertion) + var args = assertion.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries); + + switch (args[0]) { case "true": - return this; + return true; case "false": - return null; + return false; + + case "order-valid": + // Assert order was valid + + case "order-invalid": + // Assert order was invalid + + case "has-past": + // Assert a timeline's past + + case "holds": + // Assert a unit successfully held + + case "dislodged": + // Assert a unit was dislodged + + case "moves": + // Assert a unit successfully moved + + case "no-move": + // Assert a unit did not move + + case "supports": + // Assert a unit's support was given + + case "cut": + // Assert a unit's support was cut + + default: + Console.WriteLine($"Unknown assertion \"{args[0]}\""); + return !Strict; } - - Console.WriteLine("Order lookup not implemented yet"); - return this; } } diff --git a/MultiversalDiplomacyTests/ReplTest.cs b/MultiversalDiplomacyTests/ReplTest.cs index 5feed37..2460201 100644 --- a/MultiversalDiplomacyTests/ReplTest.cs +++ b/MultiversalDiplomacyTests/ReplTest.cs @@ -86,4 +86,179 @@ public class ReplTest repl["assert false"].AssertClosed(); } + + [Test] + public void AssertInvalidOrder() + { + var repl = StandardRepl(); + + repl[""" + unit Germany A Mun + --- + Germany A Mun - Mars + --- + """].AssertReady(); + + // Assertion should pass for an invalid order + repl["assert order-invalid Mun"].AssertReady(); + // Assertion should fail for an invalid order + repl["assert order-valid Mun"].AssertClosed(); + } + + [Test] + public void AssertValidOrder() + { + var repl = StandardRepl(); + + repl[""" + unit Germany A Mun + --- + Germany A Mun - Tyr + --- + """].AssertReady(); + + // Assertion should pass for a valid order + repl["assert order-valid Mun"].AssertReady(); + // Assertion should fail for a valid order + repl["assert order-invalid Mun"].AssertClosed(); + } + + [Test] + public void AssertSeasonPast() + { + var repl = StandardRepl(); + + repl[""" + unit England F London + --- + --- + """].AssertReady(); + + // Assertion should pass for a season's past + repl["assert has-past a1>a0"].AssertReady(); + // Assertion should fail for an incorrect past + repl["assert has-past a0>a1"].AssertClosed(); + } + + [Test] + public void AssertHolds() + { + var repl = StandardRepl(); + + repl[""" + unit Germany A Mun + unit Austria A Tyr + --- + Germany Mun - Tyr + --- + """].AssertReady(); + + // Assertion should pass for a repelled move + repl["assert holds Tyr"].AssertReady(); + // Assertion should fail for a repelled move + repl["assert dislodged Tyr"].AssertClosed(); + } + + [Test] + public void AssertDislodged() + { + var repl = StandardRepl(); + + repl[""" + unit Germany A Mun + unit Germany A Boh + unit Austria A Tyr + --- + Germany Mun - Tyr + Germany Boh s Mun - Tyr + --- + """].AssertReady(); + + // Assertion should pass for a dislodge + repl["assert dislodged Tyr"].AssertReady(); + // Assertion should fail for a repelled move + repl["assert holds Tyr"].AssertClosed(); + } + + [Test] + public void AssertMoves() + { + var repl = StandardRepl(); + + repl[""" + unit Germany A Mun + --- + Germany Mun - Tyr + --- + """].AssertReady(); + + // Assertion should pass for a move + repl["assert moves Mun"].AssertReady(); + // Assertion should fail for a successful move + repl["assert no-move Mun"].AssertClosed(); + } + + [Test] + public void AssertRepelled() + { + var repl = StandardRepl(); + + repl[""" + unit Germany A Mun + unit Austria A Tyr + --- + Germany Mun - Tyr + --- + """].AssertReady(); + + // Assertion should pass for a repelled move + repl["assert no-move Mun"].AssertReady(); + // Assertion should fail for no move + repl["assert moves Mun"].AssertClosed(); + } + + [Test] + public void AssertSupports() + { + var repl = StandardRepl(); + + repl[""" + unit Germany A Mun + unit Germany A Boh + unit Austria A Tyr + --- + Germany: + Mun - Tyr + Boh s Mun - Tyr + --- + """].AssertReady(); + + // `supports` and `cut` are opposites + repl["assert supports Boh"].AssertReady(); + repl["assert cut Boh"].AssertClosed(); + } + + [Test] + public void AssertCutSupport() + { + var repl = StandardRepl(); + + repl[""" + unit Germany A Mun + unit Germany A Boh + unit Austria A Tyr + unit Italy A Vienna + --- + Germany: + Mun - Tyr + Boh s Mun - Tyr + + Italy Vienna - Boh + --- + """].AssertReady(); + + // `supports` and `cut` are opposites + repl["assert cut Boh"].AssertReady(); + repl["assert supports Boh"].AssertClosed(); + } }