Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test for detecting unmapped wargoals #2308

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading