Implement support-hold parsing

This commit is contained in:
Tim Van Baak 2024-09-05 05:22:07 +00:00
parent 26f7cee070
commit ae5eb22010
2 changed files with 45 additions and 41 deletions

View File

@ -214,7 +214,8 @@ public class OrderParser(World world)
return true; return true;
} }
public static bool TryParseOrder(World world, string power, string command, [NotNullWhen(true)] out Order? order) { public static bool TryParseOrder(World world, string power, string command, [NotNullWhen(true)] out Order? order)
{
order = null; order = null;
OrderParser re = new(world); OrderParser re = new(world);
@ -346,7 +347,19 @@ public class OrderParser(World world)
{ {
order = null; order = null;
var support = ParseSupportHold(match); var support = ParseSupportHold(match);
throw new NotImplementedException();
if (!TryParseOrderSubject(world, support.timeline, support.turn, support.province, out Unit? subject)) {
return false;
}
if (!TryParseOrderSubject(
world, support.targetTimeline, support.targetTurn, support.targetProvince, out Unit? target))
{
return false;
}
order = new SupportHoldOrder(power, subject, target);
return true;
} }
public static bool TryParseSupportMoveOrder( public static bool TryParseSupportMoveOrder(

View File

@ -161,6 +161,36 @@ public class ReplTest
repl.AssertFails("assert no-move Mun"); repl.AssertFails("assert no-move Mun");
} }
[Test]
public void AssertSupportHold()
{
var repl = StandardRepl();
repl.ExecuteAll("""
unit Germany A Mun
unit Germany A Boh
unit Austria A Tyr
---
Germany Mun s Boh
---
""");
// Support is given
repl.Execute("assert support-given Mun");
repl.AssertFails("assert support-cut Mun");
repl.ExecuteAll("""
---
Germany Mun s Boh
Austria Tyr - Mun
---
""");
// Support is cut
repl.Execute("assert support-cut Mun");
repl.AssertFails("assert support-given Mun");
}
[Test] [Test]
public void AssertDislodged() public void AssertDislodged()
{ {
@ -183,45 +213,6 @@ public class ReplTest
repl.AssertFails("assert holds Tyr"); repl.AssertFails("assert holds Tyr");
} }
[Test]
public void AssertMoves()
{
Assert.Ignore();
var repl = StandardRepl();
repl.ExecuteAll("""
unit Germany A Mun
---
Germany Mun - Tyr
---
""");
// Assertion should pass for a move
repl.Execute("assert moves Mun");
// Assertion should fail for a successful move
repl.AssertFails("assert no-move Mun");
}
[Test]
public void AssertRepelled()
{
Assert.Ignore();
var repl = StandardRepl();
repl.ExecuteAll("""
unit Germany A Mun
unit Austria A Tyr
---
Germany Mun - Tyr
---
""");
// Assertion should pass for a repelled move
repl.Execute("assert no-move Mun");
// Assertion should fail for no move
repl.AssertFails("assert moves Mun");
}
[Test] [Test]
public void AssertSupports() public void AssertSupports()
{ {