5dplomacy/MultiversalDiplomacyTests/RegexTest.cs

69 lines
2.7 KiB
C#
Raw Normal View History

2024-08-20 14:39:49 +00:00
using System.Text.RegularExpressions;
using NUnit.Framework;
using MultiversalDiplomacy.Model;
namespace MultiversalDiplomacyTests;
public class RegexTest
{
[Test]
public void UnitTokenizer()
{
World world = World.WithStandardMap();
OrderRegex re = new(world);
var match = re.Hold.Match("Germany Army a-Munich/l@0 holds");
Assert.That(match.Success, Is.True);
var hold = OrderRegex.ParseHold(match);
Assert.That(hold.power, Is.EqualTo("Germany"));
Assert.That(hold.type, Is.EqualTo("Army"));
Assert.That(hold.timeline, Is.EqualTo("a"));
Assert.That(hold.province, Is.EqualTo("Munich"));
Assert.That(hold.location, Is.EqualTo("l"));
Assert.That(hold.turn, Is.EqualTo("0"));
Assert.That(hold.verb, Is.EqualTo("holds"));
match = re.Hold.Match("F Venice hold");
Assert.That(match.Success, Is.True);
hold = OrderRegex.ParseHold(match);
Assert.That(hold.power, Is.EqualTo(""));
Assert.That(hold.type, Is.EqualTo("F"));
Assert.That(hold.timeline, Is.EqualTo(""));
Assert.That(hold.province, Is.EqualTo("Venice"));
Assert.That(hold.location, Is.EqualTo(""));
Assert.That(hold.turn, Is.EqualTo(""));
Assert.That(hold.verb, Is.EqualTo("hold"));
match = re.Move.Match("F Gascony - Spain(nc)");
Assert.That(match.Success, Is.True);
var move = OrderRegex.ParseMove(match);
Assert.That(move.power, Is.EqualTo(""));
Assert.That(move.type, Is.EqualTo("F"));
Assert.That(move.timeline, Is.EqualTo(""));
Assert.That(move.province, Is.EqualTo("Gascony"));
Assert.That(move.location, Is.EqualTo(""));
Assert.That(move.turn, Is.EqualTo(""));
Assert.That(move.verb, Is.EqualTo("-"));
Assert.That(move.timeline2, Is.EqualTo(""));
Assert.That(move.province2, Is.EqualTo("Spain"));
Assert.That(move.location2, Is.EqualTo("nc"));
Assert.That(move.turn2, Is.EqualTo(""));
match = re.Move.Match("F North Sea - Picardy");
Assert.That(match.Success, Is.True);
move = OrderRegex.ParseMove(match);
Assert.That(move.power, Is.EqualTo(""));
Assert.That(move.type, Is.EqualTo("F"));
Assert.That(move.timeline, Is.EqualTo(""));
Assert.That(move.province, Is.EqualTo("North Sea"));
Assert.That(move.location, Is.EqualTo(""));
Assert.That(move.turn, Is.EqualTo(""));
Assert.That(move.verb, Is.EqualTo("-"));
Assert.That(move.timeline2, Is.EqualTo(""));
Assert.That(move.province2, Is.EqualTo("Picardy"));
Assert.That(move.location2, Is.EqualTo(""));
Assert.That(move.turn2, Is.EqualTo(""));
2024-08-20 14:39:49 +00:00
}
}