Skip to content

Commit

Permalink
Merge branch 'master' into feature/rajas-of-asia-support
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Nov 21, 2024
2 parents ad43520 + 7923f56 commit 7bc97f9
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ updates:
schedule:
interval: "weekly"

- package-ecosystem: "dotnet-sdk"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
# Workflow files stored in the
# default location of `.github/workflows`
Expand Down
38 changes: 38 additions & 0 deletions ImperatorToCK3.UnitTests/CK3/Cultures/NameListTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using commonItems;
using Xunit;

namespace ImperatorToCK3.UnitTests.CK3.Cultures;

public class NameListTests {
[Fact]
public void NameListIsCorrectlyLoaded() {
var reader = new BufferedReader("""
{
male_names = {
John
"Alexander"
2 = { Tom "Mark" }
}
female_names = {
Jane
"Alexandra"
2 = { Sandra "Maria" }
}
""");
var nameList = new ImperatorToCK3.CK3.Cultures.NameList("test", reader);

Assert.Equal("test", nameList.Id);
Assert.Collection(nameList.MaleNames,
item => Assert.Equal("John", item),
item => Assert.Equal("Alexander", item),
item => Assert.Equal("Tom", item),
item => Assert.Equal("Mark", item)
);
Assert.Collection(nameList.FemaleNames,
item => Assert.Equal("Jane", item),
item => Assert.Equal("Alexandra", item),
item => Assert.Equal("Sandra", item),
item => Assert.Equal("Maria", item)
);
}
}
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.UnitTests/ImperatorToCK3.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
17 changes: 8 additions & 9 deletions ImperatorToCK3/CK3/Cultures/NameList.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using commonItems;
using commonItems.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.RegularExpressions;

namespace ImperatorToCK3.CK3.Cultures;

public sealed partial class NameList : IIdentifiable<string> {
public string Id { get; }
private readonly OrderedSet<string> maleNames = new();
private readonly OrderedSet<string> femaleNames = new();
public IReadOnlyCollection<string> MaleNames => maleNames.ToImmutableList();
public IReadOnlyCollection<string> FemaleNames => femaleNames.ToImmutableList();
private readonly OrderedSet<string> maleNames = [];
private readonly OrderedSet<string> femaleNames = [];
public IReadOnlyCollection<string> MaleNames => maleNames;
public IReadOnlyCollection<string> FemaleNames => femaleNames;

public NameList(string id, BufferedReader nameListReader) {
Id = id;
Expand All @@ -25,8 +24,8 @@ public NameList(string id, BufferedReader nameListReader) {
maleNamesBlockParser.RegisterRegex(CommonRegexes.String, (_, nameStr) => {
maleNames.Add(nameStr);
});
maleNamesBlockParser.RegisterRegex(CommonRegexes.QuotedString, (_, nameStr) => {
maleNames.Add(nameStr);
maleNamesBlockParser.RegisterRegex(CommonRegexes.QuotedString, (_, quotedNameStr) => {
maleNames.Add(quotedNameStr.RemQuotes());
});
maleNamesBlockParser.IgnoreAndLogUnregisteredItems();
maleNamesBlockParser.ParseStream(maleNamesReader);
Expand All @@ -39,8 +38,8 @@ public NameList(string id, BufferedReader nameListReader) {
femaleNamesBlockParser.RegisterRegex(CommonRegexes.String, (_, nameStr) => {
femaleNames.Add(nameStr);
});
femaleNamesBlockParser.RegisterRegex(CommonRegexes.QuotedString, (_, nameStr) => {
femaleNames.Add(nameStr);
femaleNamesBlockParser.RegisterRegex(CommonRegexes.QuotedString, (_, quotedNameStr) => {
femaleNames.Add(quotedNameStr.RemQuotes());
});
femaleNamesBlockParser.IgnoreAndLogUnregisteredItems();
femaleNamesBlockParser.ParseStream(reader);
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Helpers/RakalyCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace ImperatorToCK3.Helpers;

public static class RakalyCaller {
private const string RakalyVersion = "0.5.3";
private const string RakalyVersion = "0.5.4";
private static readonly string RelativeRakalyPath;

static RakalyCaller() {
Expand Down
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();
}
14 changes: 7 additions & 7 deletions ImperatorToCK3/ImperatorToCK3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@
<PackageReference Include="ColorHashSharp" Version="1.0.0"/>
<PackageReference Include="ConcurrentSet" Version="1.0.0"/>
<PackageReference Include="CWTools" Version="0.5.0-alpha" />
<PackageReference Include="DotLiquid" Version="2.2.692" />
<PackageReference Include="FSharp.Core" Version="8.0.401" /> <!-- Needed for CWTools -->
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="14.0.0"/>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.177">
<PackageReference Include="DotLiquid" Version="2.2.717" />
<PackageReference Include="FSharp.Core" Version="9.0.100" /> <!-- Needed for CWTools -->
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="14.2.0"/>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.180">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PGCG.commonItems" Version="15.1.0" />
<PackageReference Include="PGCG.commonItems" Version="15.1.1" />
<PackageReference Include="PGCG.commonItems.SourceGenerators" Version="1.0.7"/>
<PackageReference Include="Polly" Version="8.4.2" />
<PackageReference Include="Polly" Version="8.5.0" />
<PackageReference Include="Roslynator.Analyzers" Version="4.12.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5"/>
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6"/>
</ItemGroup>

<ItemGroup>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion InnoDependencyInstaller
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.100-rc.2.24474.11",
"version": "9.0.100",
"allowPrerelease": true,
"rollForward": "disable"
}
Expand Down

0 comments on commit 7bc97f9

Please sign in to comment.