From e9c999926865b3b1c281b3c108e031119e6b74a6 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Tue, 3 Sep 2024 03:49:38 +0000 Subject: [PATCH] Implement assert has-past --- .../Script/AdjudicationQueryScriptHandler.cs | 14 +++++++++++++- MultiversalDiplomacyTests/ReplTest.cs | 1 - 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs b/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs index 2d14bc2..bbccf70 100644 --- a/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs +++ b/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs @@ -101,7 +101,19 @@ public class AdjudicationQueryScriptHandler( return ScriptResult.Succeed(this); case "has-past": - // Assert a timeline's past + Regex hasPast = new($"^([a-z]+[0-9]+)>([a-z]+[0-9]+)$"); + Match hpMatch = hasPast.Match(args[1]); + if (!hpMatch.Success) return ScriptResult.Fail("Expected format s1>s2", this); + + Season future = new(hpMatch.Groups[1].Value); + if (!World.Timelines.Pasts.TryGetValue(future.Key, out Season? actual)) { + return ScriptResult.Fail($"No such season \"{future}\""); + } + + Season expected = new(hpMatch.Groups[2].Value); + if (actual != expected) return ScriptResult.Fail( + $"Expected past of {future} to be {expected}, but it was {actual}"); + return ScriptResult.Succeed(this); case "holds": // Assert a unit successfully held diff --git a/MultiversalDiplomacyTests/ReplTest.cs b/MultiversalDiplomacyTests/ReplTest.cs index 738255f..330d41b 100644 --- a/MultiversalDiplomacyTests/ReplTest.cs +++ b/MultiversalDiplomacyTests/ReplTest.cs @@ -116,7 +116,6 @@ public class ReplTest [Test] public void AssertSeasonPast() { - Assert.Ignore(); var repl = StandardRepl(); repl.ExecuteAll("""