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))] [TestCaseSource(nameof(DatcTestCases))]
public void Test_DATC(string testScriptPath) public void Test_DATC(string testScriptPath)
{ {
Assert.Ignore("Script tests postponed until parsing tests are done");
string filename = Path.GetFileName(testScriptPath); string filename = Path.GetFileName(testScriptPath);
int line = 0; int line = 0;
bool expectFailure = false;
IScriptHandler handler = new SetupScriptHandler( IScriptHandler handler = new SetupScriptHandler(
(msg) => {/* discard */}, (msg) => {/* discard */},
World.WithStandardMap(), World.WithStandardMap(),
Adjudicator.MovementPhase); Adjudicator.MovementPhase);
foreach (string input in File.ReadAllLines(testScriptPath)) { foreach (string input in File.ReadAllLines(testScriptPath)) {
line++; 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); 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}"); $"Script {filename} error at line {line}: {result.Message}");
if (result.NextHandler is null) throw new AssertionException( if (result.NextHandler is null) throw new AssertionException(
$"Script {filename} quit unexpectedly at line {line}: \"{input}\""); $"Script {filename} quit unexpectedly at line {line}: \"{input}\"");
handler = result.NextHandler; handler = result.NextHandler;
expectFailure = false;
} }
} }
} }

View File

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

View File

@ -6,9 +6,10 @@ unit England A Liverpool
--- ---
England: England:
#test:fails
A Liverpool - Irish Sea A Liverpool - Irish Sea
--- ---
# Order should fail. # 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 # 6.A.3. TEST CASE, MOVE FLEET TO LAND
# Check whether a fleet cannot move to land. # Check whether a fleet cannot move to land.
unit Germany Army Kiel unit Germany F Kiel
--- ---
Germany: Germany:
#test:fails
F Kiel - Munich F Kiel - Munich
--- ---
# Order should fail. # 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 # 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."). # 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. # 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 # 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..."). # 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 F North Sea
unit England A Yorkshire unit England A Yorkshire
unit England A Liverpool unit England A Liverpool
@ -21,11 +24,11 @@ A Wales Supports F London - Yorkshire
--- ---
# The move of the army in Yorkshire is illegal. # 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. # This makes the support of Liverpool also illegal and without the support, the Germans have a stronger force.
assert North Sea holds assert hold-order North Sea
assert Liverpool holds assert hold-order Liverpool
assert London moves assert moves London
# The army in London dislodges the army in Yorkshire. # The army in London dislodges the army in Yorkshire.
assert Wales supports assert support-given Wales
assert Yorkshire dislodged assert dislodged Yorkshire

View File

@ -13,4 +13,4 @@ F London - North Sea
--- ---
# Order should fail. # 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 # 6.A.7. TEST CASE, ONLY ARMIES CAN BE CONVOYED
# A fleet cannot be convoyed. # A fleet cannot be convoyed.
# TODO convoy order parsing
#test:skip
unit England F London 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. # Move from London to Belgium should fail.
assert London holds assert hold-order London