Implement dummy assertions
This commit is contained in:
parent
f02e71d4f9
commit
d2a46aa02d
@ -17,7 +17,7 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) :
|
||||
|
||||
public IScriptHandler? HandleInput(string input)
|
||||
{
|
||||
var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
var args = input.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (args.Length == 0 || input.StartsWith('#'))
|
||||
{
|
||||
return this;
|
||||
@ -35,16 +35,7 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) :
|
||||
break;
|
||||
|
||||
case "assert":
|
||||
string assertion = input["assert ".Length..];
|
||||
Regex prov = new($"{World.Map.ProvinceRegex} (.*)");
|
||||
Match match = prov.Match(assertion);
|
||||
if (!match.Success) {
|
||||
Console.WriteLine($"Could not parse province from \"{assertion}\"");
|
||||
return Strict ? null : this;
|
||||
}
|
||||
// TODO look up order once orders are validated and adjudicated
|
||||
Console.WriteLine("Order lookup not implemented yet");
|
||||
return null;
|
||||
return HandleAssertion(args[1]);
|
||||
|
||||
case "status":
|
||||
throw new NotImplementedException();
|
||||
@ -57,4 +48,20 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) :
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private AdjudicationQueryScriptHandler? HandleAssertion(string assertion)
|
||||
{
|
||||
// Simple assertions
|
||||
switch (assertion)
|
||||
{
|
||||
case "true":
|
||||
return this;
|
||||
|
||||
case "false":
|
||||
return null;
|
||||
}
|
||||
|
||||
Console.WriteLine("Order lookup not implemented yet");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class ReplDriver(IScriptHandler initialHandler, bool echo = false)
|
||||
bool Echo { get; } = echo;
|
||||
|
||||
/// <summary>
|
||||
/// Input a multiline string into the repl. Call <see cref="Ready"/> or <see cref="Closed"/> at the end so the
|
||||
/// Input a multiline string into the repl. Call <see cref="AssertReady"/> or <see cref="AssertClosed"/> at the end so the
|
||||
/// statement is valid.
|
||||
/// </summary>
|
||||
public ReplDriver this[string input] => ExecuteAll(input);
|
||||
@ -39,13 +39,13 @@ public class ReplDriver(IScriptHandler initialHandler, bool echo = false)
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Ready()
|
||||
public void AssertReady()
|
||||
{
|
||||
Assert.That(Handler, Is.Not.Null, "Handler is closed");
|
||||
if (Handler is null) Assert.Fail($"Handler terminated after \"{LastInput}\"");
|
||||
}
|
||||
|
||||
public void Closed()
|
||||
public void AssertClosed()
|
||||
{
|
||||
Assert.That(Handler, Is.Null, "Handler is not closed");
|
||||
if (Handler is not null) Assert.Fail($"Handler did not terminate after \"{LastInput}\"");
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class ReplTest
|
||||
unit Germany A Munich
|
||||
unit Austria Army Tyrolia
|
||||
unit England F Lon
|
||||
"""].Ready();
|
||||
"""].AssertReady();
|
||||
|
||||
Assert.That(repl.Handler, Is.TypeOf<SetupScriptHandler>());
|
||||
SetupScriptHandler handler = (SetupScriptHandler)repl.Handler!;
|
||||
@ -29,7 +29,7 @@ public class ReplTest
|
||||
|
||||
repl["""
|
||||
---
|
||||
"""].Ready();
|
||||
"""].AssertReady();
|
||||
|
||||
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
|
||||
}
|
||||
@ -50,7 +50,7 @@ public class ReplTest
|
||||
Austria: Army Tyrolia - Vienna
|
||||
England:
|
||||
Lon h
|
||||
"""].Ready();
|
||||
"""].AssertReady();
|
||||
|
||||
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
|
||||
GameScriptHandler handler = (GameScriptHandler)repl.Handler!;
|
||||
@ -64,11 +64,23 @@ public class ReplTest
|
||||
|
||||
repl["""
|
||||
---
|
||||
"""].Ready();
|
||||
"""].AssertReady();
|
||||
|
||||
Assert.That(repl.Handler, Is.TypeOf<AdjudicationQueryScriptHandler>());
|
||||
var newHandler = (AdjudicationQueryScriptHandler)repl.Handler!;
|
||||
Assert.That(newHandler.World, Is.Not.EqualTo(before));
|
||||
Assert.That(newHandler.World.Timelines.Pasts.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertBasic()
|
||||
{
|
||||
var repl = new ReplDriver(new SetupScriptHandler(World.WithStandardMap(), strict: true))["""
|
||||
unit Germany A Munich
|
||||
---
|
||||
---
|
||||
"""];
|
||||
repl["assert true"].AssertReady();
|
||||
repl["assert false"].AssertClosed();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user