From 5e2d495fa50b42ecb721ed12258bfc306df85664 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 6 Sep 2024 16:04:25 +0000 Subject: [PATCH] Update script tests --- MultiversalDiplomacyTests/ScriptTests.cs | 20 +++++++++++++++++-- .../Scripts/DATC/6.A.1.txt | 2 +- .../Scripts/DATC/6.A.2.txt | 3 ++- .../Scripts/DATC/6.A.3.txt | 5 +++-- .../Scripts/DATC/6.A.4.txt | 4 ++-- .../Scripts/DATC/6.A.5.txt | 15 ++++++++------ .../Scripts/DATC/6.A.6.txt | 2 +- .../Scripts/DATC/6.A.7.txt | 7 +++++-- 8 files changed, 41 insertions(+), 17 deletions(-) diff --git a/MultiversalDiplomacyTests/ScriptTests.cs b/MultiversalDiplomacyTests/ScriptTests.cs index c9afade..4e790f7 100644 --- a/MultiversalDiplomacyTests/ScriptTests.cs +++ b/MultiversalDiplomacyTests/ScriptTests.cs @@ -19,21 +19,37 @@ public class ScriptTests [TestCaseSource(nameof(DatcTestCases))] public void Test_DATC(string testScriptPath) { - Assert.Ignore("Script tests postponed until parsing tests are done"); string filename = Path.GetFileName(testScriptPath); int line = 0; + bool expectFailure = false; + IScriptHandler handler = new SetupScriptHandler( (msg) => {/* discard */}, World.WithStandardMap(), Adjudicator.MovementPhase); + foreach (string input in File.ReadAllLines(testScriptPath)) { line++; + + // Handle test directives + if (input == "#test:skip") { + Assert.Ignore($"Script {filename} skipped at line {line}"); + } + if (input == "#test:fails") { + expectFailure = true; + continue; + } + var result = handler.HandleInput(input); - if (!result.Success) throw new AssertionException( + if (expectFailure && result.Success) throw new AssertionException( + $"Script {filename} expected line {line} to fail, but it succeeded"); + if (!expectFailure && !result.Success) throw new AssertionException( $"Script {filename} error at line {line}: {result.Message}"); if (result.NextHandler is null) throw new AssertionException( $"Script {filename} quit unexpectedly at line {line}: \"{input}\""); + handler = result.NextHandler; + expectFailure = false; } } } diff --git a/MultiversalDiplomacyTests/Scripts/DATC/6.A.1.txt b/MultiversalDiplomacyTests/Scripts/DATC/6.A.1.txt index 3352544..b5feb72 100644 --- a/MultiversalDiplomacyTests/Scripts/DATC/6.A.1.txt +++ b/MultiversalDiplomacyTests/Scripts/DATC/6.A.1.txt @@ -11,4 +11,4 @@ F North Sea - Picardy --- # Order should fail. -assert North Sea holds +assert hold-order North Sea diff --git a/MultiversalDiplomacyTests/Scripts/DATC/6.A.2.txt b/MultiversalDiplomacyTests/Scripts/DATC/6.A.2.txt index 527d035..4967325 100644 --- a/MultiversalDiplomacyTests/Scripts/DATC/6.A.2.txt +++ b/MultiversalDiplomacyTests/Scripts/DATC/6.A.2.txt @@ -6,9 +6,10 @@ unit England A Liverpool --- England: +#test:fails A Liverpool - Irish Sea --- # Order should fail. -assert Liverpool holds +assert hold-order Liverpool diff --git a/MultiversalDiplomacyTests/Scripts/DATC/6.A.3.txt b/MultiversalDiplomacyTests/Scripts/DATC/6.A.3.txt index d160bef..af7fe42 100644 --- a/MultiversalDiplomacyTests/Scripts/DATC/6.A.3.txt +++ b/MultiversalDiplomacyTests/Scripts/DATC/6.A.3.txt @@ -1,14 +1,15 @@ # 6.A.3. TEST CASE, MOVE FLEET TO LAND # Check whether a fleet cannot move to land. -unit Germany Army Kiel +unit Germany F Kiel --- Germany: +#test:fails F Kiel - Munich --- # Order should fail. -assert Kiel holds +assert hold-order Kiel diff --git a/MultiversalDiplomacyTests/Scripts/DATC/6.A.4.txt b/MultiversalDiplomacyTests/Scripts/DATC/6.A.4.txt index 3ff5c48..c53f886 100644 --- a/MultiversalDiplomacyTests/Scripts/DATC/6.A.4.txt +++ b/MultiversalDiplomacyTests/Scripts/DATC/6.A.4.txt @@ -1,7 +1,7 @@ # 6.A.4. TEST CASE, MOVE TO OWN SECTOR # Moving to the same sector is an illegal move (2023 rulebook, page 7, "An Army can be ordered to move into an adjacent inland or coastal province."). -unit Germany Army Kiel +unit Germany F Kiel --- @@ -11,4 +11,4 @@ F Kiel - Kiel --- # Program should not crash. -assert Kiel holds +assert hold-order Kiel diff --git a/MultiversalDiplomacyTests/Scripts/DATC/6.A.5.txt b/MultiversalDiplomacyTests/Scripts/DATC/6.A.5.txt index 8eb3c6b..807cffe 100644 --- a/MultiversalDiplomacyTests/Scripts/DATC/6.A.5.txt +++ b/MultiversalDiplomacyTests/Scripts/DATC/6.A.5.txt @@ -1,6 +1,9 @@ # 6.A.5. TEST CASE, MOVE TO OWN SECTOR WITH CONVOY # Moving to the same sector is still illegal with convoy (2023 rulebook, page 7, "Note: An Army can move across water provinces from one coastal province to another..."). +# TODO convoy order parsing +#test:skip + unit England F North Sea unit England A Yorkshire unit England A Liverpool @@ -21,11 +24,11 @@ A Wales Supports F London - Yorkshire --- # The move of the army in Yorkshire is illegal. -assert Yorkshire holds +assert hold-order Yorkshire # This makes the support of Liverpool also illegal and without the support, the Germans have a stronger force. -assert North Sea holds -assert Liverpool holds -assert London moves +assert hold-order North Sea +assert hold-order Liverpool +assert moves London # The army in London dislodges the army in Yorkshire. -assert Wales supports -assert Yorkshire dislodged +assert support-given Wales +assert dislodged Yorkshire diff --git a/MultiversalDiplomacyTests/Scripts/DATC/6.A.6.txt b/MultiversalDiplomacyTests/Scripts/DATC/6.A.6.txt index cc01be9..832ec47 100644 --- a/MultiversalDiplomacyTests/Scripts/DATC/6.A.6.txt +++ b/MultiversalDiplomacyTests/Scripts/DATC/6.A.6.txt @@ -13,4 +13,4 @@ F London - North Sea --- # Order should fail. -assert London holds +assert hold-order London diff --git a/MultiversalDiplomacyTests/Scripts/DATC/6.A.7.txt b/MultiversalDiplomacyTests/Scripts/DATC/6.A.7.txt index 3057bde..1ec1303 100644 --- a/MultiversalDiplomacyTests/Scripts/DATC/6.A.7.txt +++ b/MultiversalDiplomacyTests/Scripts/DATC/6.A.7.txt @@ -1,8 +1,11 @@ # 6.A.7. TEST CASE, ONLY ARMIES CAN BE CONVOYED # A fleet cannot be convoyed. +# TODO convoy order parsing +#test:skip + unit England F London -unit England North Sea +unit England F North Sea --- @@ -13,4 +16,4 @@ F North Sea Convoys A London - Belgium --- # Move from London to Belgium should fail. -assert London holds +assert hold-order London