Update script tests

This commit is contained in:
Tim Van Baak 2024-09-06 16:04:25 +00:00
parent 7773c571e3
commit 5e2d495fa5
8 changed files with 41 additions and 17 deletions

View File

@ -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;
}
}
}

View File

@ -11,4 +11,4 @@ F North Sea - Picardy
---
# Order should fail.
assert North Sea holds
assert hold-order North Sea

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -13,4 +13,4 @@ F London - North Sea
---
# Order should fail.
assert London holds
assert hold-order London

View File

@ -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