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)
|
public IScriptHandler? HandleInput(string input)
|
||||||
{
|
{
|
||||||
var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
var args = input.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (args.Length == 0 || input.StartsWith('#'))
|
if (args.Length == 0 || input.StartsWith('#'))
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
|
@ -35,16 +35,7 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) :
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "assert":
|
case "assert":
|
||||||
string assertion = input["assert ".Length..];
|
return HandleAssertion(args[1]);
|
||||||
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;
|
|
||||||
|
|
||||||
case "status":
|
case "status":
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@ -57,4 +48,20 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) :
|
||||||
|
|
||||||
return this;
|
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;
|
bool Echo { get; } = echo;
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// statement is valid.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ReplDriver this[string input] => ExecuteAll(input);
|
public ReplDriver this[string input] => ExecuteAll(input);
|
||||||
|
@ -39,13 +39,13 @@ public class ReplDriver(IScriptHandler initialHandler, bool echo = false)
|
||||||
return this;
|
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 Germany A Munich
|
||||||
unit Austria Army Tyrolia
|
unit Austria Army Tyrolia
|
||||||
unit England F Lon
|
unit England F Lon
|
||||||
"""].Ready();
|
"""].AssertReady();
|
||||||
|
|
||||||
Assert.That(repl.Handler, Is.TypeOf<SetupScriptHandler>());
|
Assert.That(repl.Handler, Is.TypeOf<SetupScriptHandler>());
|
||||||
SetupScriptHandler handler = (SetupScriptHandler)repl.Handler!;
|
SetupScriptHandler handler = (SetupScriptHandler)repl.Handler!;
|
||||||
|
@ -29,7 +29,7 @@ public class ReplTest
|
||||||
|
|
||||||
repl["""
|
repl["""
|
||||||
---
|
---
|
||||||
"""].Ready();
|
"""].AssertReady();
|
||||||
|
|
||||||
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
|
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class ReplTest
|
||||||
Austria: Army Tyrolia - Vienna
|
Austria: Army Tyrolia - Vienna
|
||||||
England:
|
England:
|
||||||
Lon h
|
Lon h
|
||||||
"""].Ready();
|
"""].AssertReady();
|
||||||
|
|
||||||
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
|
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
|
||||||
GameScriptHandler handler = (GameScriptHandler)repl.Handler!;
|
GameScriptHandler handler = (GameScriptHandler)repl.Handler!;
|
||||||
|
@ -64,11 +64,23 @@ public class ReplTest
|
||||||
|
|
||||||
repl["""
|
repl["""
|
||||||
---
|
---
|
||||||
"""].Ready();
|
"""].AssertReady();
|
||||||
|
|
||||||
Assert.That(repl.Handler, Is.TypeOf<AdjudicationQueryScriptHandler>());
|
Assert.That(repl.Handler, Is.TypeOf<AdjudicationQueryScriptHandler>());
|
||||||
var newHandler = (AdjudicationQueryScriptHandler)repl.Handler!;
|
var newHandler = (AdjudicationQueryScriptHandler)repl.Handler!;
|
||||||
Assert.That(newHandler.World, Is.Not.EqualTo(before));
|
Assert.That(newHandler.World, Is.Not.EqualTo(before));
|
||||||
Assert.That(newHandler.World.Timelines.Pasts.Count, Is.EqualTo(2));
|
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