Skip to content

Commit

Permalink
More unit tests for the loading of I:R diplomacy (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Nov 11, 2024
1 parent 8edf8bc commit 1725bd4
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 32 deletions.
102 changes: 102 additions & 0 deletions ImperatorToCK3.UnitTests/Imperator/Diplomacy/DiplomacyDBTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using commonItems;
using System;
using System.IO;
using Xunit;

namespace ImperatorToCK3.UnitTests.Imperator.Diplomacy;

[Collection("Sequential")]
[CollectionDefinition("Sequential", DisableParallelization = true)]
public class DiplomacyDBTests {
[Fact]
public void WarWithNoAttackersIsSkipped() {
var output = new StringWriter();
Console.SetOut(output);

var reader = new BufferedReader("""
database = {
1 = { previous=no }
2 = { previous=no defender=1 }
}
""");
var diplomacy = new ImperatorToCK3.Imperator.Diplomacy.DiplomacyDB(reader);

Assert.Empty(diplomacy.Wars);
var logStr = output.ToString();
Assert.Contains("[DEBUG] Skipping war 1 has no attackers!", logStr);
Assert.Contains("[DEBUG] Skipping war 2 has no attackers!", logStr);
}

[Fact]
public void WarWithNoDefendersIsSkipped() {
var output = new StringWriter();
Console.SetOut(output);

var reader = new BufferedReader("""
database = {
1 = { previous=no attacker=1 }
}
""");
var diplomacy = new ImperatorToCK3.Imperator.Diplomacy.DiplomacyDB(reader);

Assert.Empty(diplomacy.Wars);
var logStr = output.ToString();
Assert.Contains("[DEBUG] Skipping war 1 has no defenders!", logStr);
}

[Fact]
public void WarWithNoWarGoalIsSkipped() {
var output = new StringWriter();
Console.SetOut(output);

var reader = new BufferedReader("""
database = {
1 = { previous=no attacker=1 defender=2 }
}
""");
var diplomacy = new ImperatorToCK3.Imperator.Diplomacy.DiplomacyDB(reader);

Assert.Empty(diplomacy.Wars);
var logStr = output.ToString();
Assert.Contains("[WARN] Skipping war 1 with no wargoal!", logStr);
}

[Fact]
public void PreviousWarsAreSkipped() {
var reader = new BufferedReader("database = { 1 = { previous=yes } }");
var diplomacy = new ImperatorToCK3.Imperator.Diplomacy.DiplomacyDB(reader);

Assert.Empty(diplomacy.Wars);
}

[Fact]
public void WarCanBeLoaded() {
var reader = new BufferedReader("""
database = {
1 = {
attacker=1 defender=2 start_date=1.1.1 take_province={ type="conquer_wargoal" state=3 }
}
}
""");
var diplomacy = new ImperatorToCK3.Imperator.Diplomacy.DiplomacyDB(reader);

Assert.Single(diplomacy.Wars);
Assert.Equal(new Date("1.1.1", AUC: true), diplomacy.Wars[0].StartDate);
Assert.Equal((ulong)1, diplomacy.Wars[0].AttackerCountryIds[0]);
Assert.Equal((ulong)2, diplomacy.Wars[0].DefenderCountryIds[0]);
Assert.Equal("conquer_wargoal", diplomacy.Wars[0].WarGoal);
Assert.Equal((ulong)3, diplomacy.Wars[0].TargetedStateId);
}

[Fact]
public void DependencyCanBeLoaded() {
var reader = new BufferedReader("dependency = { first=1 second=2 start_date=1.1.1 subject_type=tributary }");
var diplomacy = new ImperatorToCK3.Imperator.Diplomacy.DiplomacyDB(reader);

Assert.Single(diplomacy.Dependencies);
Assert.Equal((ulong)1, diplomacy.Dependencies[0].OverlordId);
Assert.Equal((ulong)2, diplomacy.Dependencies[0].SubjectId);
Assert.Equal(new Date("1.1.1", AUC: true), diplomacy.Dependencies[0].StartDate);
Assert.Equal("tributary", diplomacy.Dependencies[0].SubjectType);
}
}
31 changes: 0 additions & 31 deletions ImperatorToCK3.UnitTests/Imperator/Diplomacy/DiplomacyTests.cs

This file was deleted.

2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Diplomacy/DiplomacyDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ private void LoadDependency(BufferedReader dependencyReader) {
dependencies.Add(new(overlordId, subjectId, startDate, subjectType));
}

private readonly IgnoredKeywordsSet ignoredTokens = new();
private readonly IgnoredKeywordsSet ignoredTokens = [];
private readonly IgnoredKeywordsSet ignoredDatabaseTokens = new();
}

0 comments on commit 1725bd4

Please sign in to comment.