Skip to content

Commit

Permalink
Unit test for detecting unmapped wargoals (#2308)
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Nov 10, 2024
1 parent 8cf47f1 commit 13dd5cc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
20 changes: 19 additions & 1 deletion ImperatorToCK3.UnitTests/Mappers/War/WarMapperTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.IO;
using commonItems.Mods;
using System.IO;
using ImperatorToCK3.Mappers.War;
using System;
using Xunit;

namespace ImperatorToCK3.UnitTests.Mappers.War;
Expand Down Expand Up @@ -58,4 +60,20 @@ public void MappingsAreReadFromFile() {
Assert.Equal("vassalization_cb", mapper.GetCK3CBForImperatorWarGoal("imperial_conquest_wargoal"));
Assert.Equal("imperial_reconquest_cb", mapper.GetCK3CBForImperatorWarGoal("diadochi_wargoal"));
}

[Fact]
public void UnmappedWarGoalsAreLogged() {
var mapper = new WarMapper("TestFiles/configurables/wargoal_mappings.txt");

var irModFS = new ModFilesystem("TestFiles/Imperator/game", Array.Empty<Mod>());

var output = new StringWriter();
Console.SetOut(output);

mapper.DetectUnmappedWarGoals(irModFS);

var outputString = output.ToString();
Assert.DoesNotContain("No mapping for war goal independence_wargoal found in war goal mappings!", outputString);
Assert.Contains("No mapping for war goal unmapped_wargoal found in war goal mappings!", outputString);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
independence_wargoal = {}

unmapped_wargoal = {}
1 change: 1 addition & 0 deletions ImperatorToCK3.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AI/@EntryIndexedValue">AI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BC/@EntryIndexedValue">BC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BOM/@EntryIndexedValue">BOM</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CB/@EntryIndexedValue">CB</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CCU/@EntryIndexedValue">CCU</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CK/@EntryIndexedValue">CK</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DB/@EntryIndexedValue">DB</s:String>
Expand Down
6 changes: 3 additions & 3 deletions ImperatorToCK3/Mappers/War/WarMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
namespace ImperatorToCK3.Mappers.War;

internal sealed class WarMapping {
public SortedSet<string> ImperatorWarGoals { get; set; } = new();
public string? CK3CasusBelli { get; set; }
public SortedSet<string> ImperatorWarGoals { get; } = [];
public string? CK3CasusBelli { get; private set; }

static WarMapping() {
parser.RegisterKeyword("ck3", reader => mappingToReturn.CK3CasusBelli = reader.GetString());
parser.RegisterKeyword("ir", reader => mappingToReturn.ImperatorWarGoals.Add(reader.GetString()));
parser.IgnoreAndLogUnregisteredItems();
}
public static WarMapping Parse (BufferedReader reader) {
public static WarMapping Parse(BufferedReader reader) {
mappingToReturn = new WarMapping();
parser.ParseStream(reader);
return mappingToReturn;
Expand Down

0 comments on commit 13dd5cc

Please sign in to comment.