diff --git a/ImperatorToCK3.UnitTests/CK3/Cultures/NameListTests.cs b/ImperatorToCK3.UnitTests/CK3/Cultures/NameListTests.cs new file mode 100644 index 000000000..4dc3edfbc --- /dev/null +++ b/ImperatorToCK3.UnitTests/CK3/Cultures/NameListTests.cs @@ -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) + ); + } +} \ No newline at end of file diff --git a/ImperatorToCK3/CK3/Cultures/NameList.cs b/ImperatorToCK3/CK3/Cultures/NameList.cs index 5858fc71f..8a753c61f 100644 --- a/ImperatorToCK3/CK3/Cultures/NameList.cs +++ b/ImperatorToCK3/CK3/Cultures/NameList.cs @@ -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 { public string Id { get; } - private readonly OrderedSet maleNames = new(); - private readonly OrderedSet femaleNames = new(); - public IReadOnlyCollection MaleNames => maleNames.ToImmutableList(); - public IReadOnlyCollection FemaleNames => femaleNames.ToImmutableList(); + private readonly OrderedSet maleNames = []; + private readonly OrderedSet femaleNames = []; + public IReadOnlyCollection MaleNames => maleNames; + public IReadOnlyCollection FemaleNames => femaleNames; public NameList(string id, BufferedReader nameListReader) { Id = id; @@ -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); @@ -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);