Skip to content

Commit

Permalink
Merge pull request #203 from AlamoEngine-Tools/develop
Browse files Browse the repository at this point in the history
Update Deps
  • Loading branch information
AnakinRaW authored Nov 13, 2024
2 parents d82def3 + 2749520 commit 3c4a12a
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/EawModinfo.Tests/MergeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void MergeInto_VariantDefinesNameOnly()
Assert.Equal(mainData.Icon, newData.Icon);
Assert.Equal(mainData.Summary, newData.Summary);
Assert.Equal(2, newData.Languages.Count); // As stated by the specification in III.3.2, languages was not explicitly set.
Assert.True(newData.LanguagesExplicitlySet);
Assert.Equal(LanguageInfo.Default, newData.Languages.First());
Assert.Equal(2, newData.Dependencies.Count);
Assert.Equal("bla", newData.Dependencies[0].Identifier);
Expand Down Expand Up @@ -89,7 +90,8 @@ public void MergeInto_VariantDefinesAll()
Assert.Equal(variantData.Name, newData.Name);
Assert.Equal(variantData.Icon, newData.Icon);
Assert.Equal(variantData.Summary, newData.Summary);
Assert.Equal(2, newData.Languages.Count());
Assert.Equal(2, newData.Languages.Count);
Assert.True(newData.LanguagesExplicitlySet);
Assert.Equal(2, newData.Dependencies.Count);
Assert.Equal("bar", newData.Dependencies[0].Identifier);
Assert.NotNull(newData.SteamData);
Expand Down Expand Up @@ -172,6 +174,7 @@ internal class InvalidModinfo : IModinfo
public IDictionary<string, object> Custom => null!;
public ISteamData? SteamData => null;
public IReadOnlyCollection<ILanguageInfo> Languages => null!;
public bool LanguagesExplicitlySet => false;

public string ToJson() => string.Empty;
public void ToJson(Stream stream)
Expand Down
26 changes: 25 additions & 1 deletion src/EawModinfo.Tests/ModinfoDataTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ public void Parse_WithOneLanguage()
var modinfo = ModinfoData.Parse(data);
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Single(modinfo.Languages);
Assert.True(modinfo.LanguagesExplicitlySet);

modinfo = ModinfoData.Parse(new MemoryStream(Encoding.UTF8.GetBytes(data)));
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Null(modinfo.Version);
Assert.Null(modinfo.SteamData);
Assert.True(modinfo.LanguagesExplicitlySet);
}

[Fact]
Expand All @@ -155,12 +157,14 @@ public void Parse_WithManyLanguages()

var modinfo = ModinfoData.Parse(data);
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Equal(2, modinfo.Languages.Count());
Assert.Equal(2, modinfo.Languages.Count);
Assert.True(modinfo.LanguagesExplicitlySet);

modinfo = ModinfoData.Parse(new MemoryStream(Encoding.UTF8.GetBytes(data)));
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Null(modinfo.Version);
Assert.Null(modinfo.SteamData);
Assert.True(modinfo.LanguagesExplicitlySet);
}

[Fact]
Expand All @@ -184,10 +188,12 @@ public void Parse_WithDuplicateLanguage()
var modinfo = ModinfoData.Parse(data);
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Single(modinfo.Languages);
Assert.True(modinfo.LanguagesExplicitlySet);

modinfo = ModinfoData.Parse(new MemoryStream(Encoding.UTF8.GetBytes(data)));
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Single(modinfo.Languages);
Assert.True(modinfo.LanguagesExplicitlySet);
}

[Fact]
Expand All @@ -212,10 +218,12 @@ public void Parse_WithDuplicateLanguage2()
var modinfo = ModinfoData.Parse(data);
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Single(modinfo.Languages);
Assert.True(modinfo.LanguagesExplicitlySet);

modinfo = ModinfoData.Parse(new MemoryStream(Encoding.UTF8.GetBytes(data)));
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Single(modinfo.Languages);
Assert.True(modinfo.LanguagesExplicitlySet);
}

[Fact]
Expand All @@ -233,12 +241,14 @@ public void Parse_WithoutLanguage()
Assert.Single(modinfo.Languages);
Assert.Equal("en", modinfo.Languages.ElementAt(0).Code);
Assert.Equal(LanguageSupportLevel.FullLocalized, modinfo.Languages.ElementAt(0).Support);
Assert.False(modinfo.LanguagesExplicitlySet);

modinfo = ModinfoData.Parse(new MemoryStream(Encoding.UTF8.GetBytes(data)));
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Single(modinfo.Languages);
Assert.Equal("en", modinfo.Languages.ElementAt(0).Code);
Assert.Equal(LanguageSupportLevel.FullLocalized, modinfo.Languages.ElementAt(0).Support);
Assert.False(modinfo.LanguagesExplicitlySet);
}

[Fact]
Expand All @@ -255,11 +265,13 @@ public void Parse_WithEmptyLanguage()
var modinfo = ModinfoData.Parse(data);
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Single(modinfo.Languages);
Assert.False(modinfo.LanguagesExplicitlySet);

modinfo = ModinfoData.Parse(new MemoryStream(Encoding.UTF8.GetBytes(data)));
Assert.Equal("My Mod Name", modinfo.Name);
Assert.Null(modinfo.Version);
Assert.Null(modinfo.SteamData);
Assert.False(modinfo.LanguagesExplicitlySet);
}

[Fact]
Expand Down Expand Up @@ -804,6 +816,8 @@ public void ToJson_Full()
},
SteamData = new SteamData("123", "folder", SteamWorkshopVisibility.Public, "Test", ["FOC"])
};

Assert.True(modinfo.LanguagesExplicitlySet);
var data = modinfo.ToJson();
output.WriteLine(data);

Expand Down Expand Up @@ -856,6 +870,7 @@ public void ToJson_CustomDefaultLanguageOnly()
new LanguageInfo("en", 0),
}
};
Assert.True(modinfo.LanguagesExplicitlySet);
var data = modinfo.ToJson();
Assert.DoesNotContain(@"""languages""", data);
output.WriteLine(data);
Expand All @@ -874,6 +889,8 @@ public void ToJson_DefaultOnlyLanguage()
LanguageInfo.Default
}
};
Assert.True(modinfo.LanguagesExplicitlySet);

var data = modinfo.ToJson();
Assert.DoesNotContain(@"""languages""", data);
output.WriteLine(data);
Expand Down Expand Up @@ -952,6 +969,7 @@ public void Ctor_Copy()
Assert.Equal(SteamWorkshopVisibility.Public, modinfo.SteamData.Visibility);
Assert.Equal("Test", modinfo.SteamData.Title);
Assert.Equivalent(new List<string>{"FOC"}, modinfo.SteamData.Tags, true);
Assert.True(modinfo.LanguagesExplicitlySet);

var other = new ModinfoData(modinfo);

Expand All @@ -965,6 +983,7 @@ public void Ctor_Copy()
Assert.Equal(modinfo.SteamData.Visibility, other.SteamData.Visibility);
Assert.Equal(modinfo.SteamData.Title, other.SteamData.Title);
Assert.Equivalent(modinfo.SteamData.Tags, other.SteamData.Tags, true);
Assert.True(other.LanguagesExplicitlySet);
}

[Fact]
Expand All @@ -973,14 +992,17 @@ public void Ctor_EmptyLanguage_ShouldFallbackToDefault()
var modinfo = new ModinfoData("name") { Languages = [] };
var lang = Assert.Single(modinfo.Languages);
Assert.Equal(LanguageInfo.Default, lang);
Assert.False(modinfo.LanguagesExplicitlySet);

var newInfo = new ModinfoData(modinfo);
lang = Assert.Single(newInfo.Languages);
Assert.Equal(LanguageInfo.Default, lang);
Assert.False(modinfo.LanguagesExplicitlySet);

var newParsed = ModinfoData.Parse(newInfo.ToJson());
lang = Assert.Single(newParsed.Languages);
Assert.Equal(LanguageInfo.Default, lang);
Assert.False(modinfo.LanguagesExplicitlySet);
}

[Fact]
Expand Down Expand Up @@ -1037,6 +1059,7 @@ public void ToJsonFromJson()
Assert.Equal(modinfo.Summary, other.Summary);
Assert.Equal(modinfo.Icon, other.Icon);
Assert.Equal(modinfo.Languages, other.Languages);
Assert.True(other.LanguagesExplicitlySet);
Assert.Equal(modinfo.SteamData.Id, other.SteamData!.Id);
Assert.Equal(modinfo.SteamData.ContentFolder, other.SteamData.ContentFolder);
Assert.Equal(modinfo.SteamData.Visibility, other.SteamData.Visibility);
Expand Down Expand Up @@ -1072,6 +1095,7 @@ public void Ctor_FromIdentity()
Assert.Equal([new ModReference("1", ModType.Default), new ModReference("2", ModType.Workshops, SemVersionRange.Parse("*"))], modinfo.Dependencies.ToList());
Assert.Equivalent(new Dictionary<string, string>(), modinfo.Custom, true);
Assert.Equal([LanguageInfo.Default], modinfo.Languages);
Assert.False(modinfo.LanguagesExplicitlySet);
Assert.Null(modinfo.Icon);
Assert.Null(modinfo.SteamData);
Assert.Null(modinfo.Summary);
Expand Down
2 changes: 2 additions & 0 deletions src/EawModinfo.Tests/VariantModinfoFileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private async Task AssertMergeDataFromMainIntoVariant(ModinfoVariantFile variant
Assert.Equal(SemVersion.ParsedFrom(1, 1, 1, "BETA"), data.Version);
Assert.Single(data.Custom);
Assert.Equal(2, data.Languages.Count);
Assert.True(data.LanguagesExplicitlySet);
}

[Fact]
Expand Down Expand Up @@ -169,5 +170,6 @@ public void MergeMainIntoVariant_WhereVariantSetsLanguageExplicitly()

var variant = variantFile.GetModinfo();
Assert.Single(variant.Languages);
Assert.True(variant.LanguagesExplicitlySet);
}
}
4 changes: 2 additions & 2 deletions src/EawModinfo/EawModinfo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
</PackageReference>
<PackageReference Include="Semver" Version="3.0.0" />
<PackageReference Include="System.IO.Abstractions" Version="21.1.3" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageReference Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
Expand Down
3 changes: 3 additions & 0 deletions src/EawModinfo/Model/Json/JsonModinfoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public IReadOnlyCollection<ILanguageInfo> Languages
}
}

[JsonIgnore]
public bool LanguagesExplicitlySet => !ReferenceEquals(Languages, ModinfoData.UnsetLanguages);

/// <inheritdoc/>
[JsonPropertyName("custom")]
public IDictionary<string, object> Custom { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion src/EawModinfo/Model/ModinfoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public IReadOnlyCollection<ILanguageInfo> Languages
}
}

/// <inheritdoc />
public bool LanguagesExplicitlySet => !ReferenceEquals(Languages, UnsetLanguages);

/// <summary>
/// Initializes a new instance of the <see cref="ModinfoData"/> class with a given name.
/// </summary>
Expand Down Expand Up @@ -110,7 +113,7 @@ public ModinfoData(IModinfo modinfo)
SteamData = modinfo.SteamData != null ? new SteamData(modinfo.SteamData) : null;
Custom = new Dictionary<string, object>(modinfo.Custom);

if (ReferenceEquals(modinfo.Languages, UnsetLanguages) || modinfo.Languages.Count == 0)
if (!modinfo.LanguagesExplicitlySet || modinfo.Languages.Count == 0)
return;
Languages = modinfo.Languages.Select(x => new LanguageInfo(x)).Distinct().ToList();
}
Expand Down
6 changes: 6 additions & 0 deletions src/EawModinfo/Spec/IModiInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ public interface IModinfo : IModIdentity, IConvertibleToJson
/// If no other language infos are provided, a default language info gets returned. The default language info is English - FullLocalized.
/// </remarks>
IReadOnlyCollection<ILanguageInfo> Languages { get; }

/// <summary>
/// Returns <see langword="true"/> if <see cref="Languages"/> was explicitly set,
/// or <see langword="false"/> is the default (English - FullLocalized) was implicitly applied.
/// </summary>
bool LanguagesExplicitlySet { get; }
}
2 changes: 1 addition & 1 deletion src/EawModinfo/Utilities/ModInfoDataUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static ModinfoData MergeFrom(IModinfo current, IModinfo target)
dependencies = new DependencyList(target.Dependencies);

var languages = current.Languages;
if (!ReferenceEquals(target.Languages, ModinfoData.UnsetLanguages))
if (target.LanguagesExplicitlySet)
languages = target.Languages.Select(x => (ILanguageInfo)new LanguageInfo(x)).Distinct().ToList();

return new ModinfoData(name)
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "6.0",
"version": "6.1",
"publicReleaseRefSpec": [
"^refs/heads/master$"
],
Expand Down

0 comments on commit 3c4a12a

Please sign in to comment.