ModernUO/Projects/Server.Tests/Tests/Localization/LocalizationEntryTests.cs
Kamron Batman 79f736aa83
fix: keep the fallback localization table registered when emptied (#2724)
## Summary
`Localization.Remove` drops a language's dictionary from `_localizations` once its last entry is removed. For the fallback language (`enu`), `_fallbackEntries` still pointed at the dropped dictionary. A later `Add("enu", ...)` then created a new dictionary, and because `_fallbackEntries` was not null, `Add`'s `??=` left it on the old one. Every fallback lookup missed the new entries.

The fallback table now stays registered when it empties. Later adds land in the dictionary lookups read, and removed entries stay removed. Nulling `_fallbackEntries` instead would have made the next lookup reload `cliloc.enu` from disk and bring back the removed entries.

Nothing in production calls `Remove` today. It is public API for shards and tests; #2722 adds a test cleanup that removes entries.

## Tests
- `LocalizationEntryTests.RemovingTheLastFallbackEntry_KeepsLaterAddsVisible` clears the tables, adds then removes one `enu` entry, adds another, and checks that the fallback lookup finds the new entry and not the removed one. It clears again afterwards so later tests reload the real tables. It fails without the fix.
- Server.Tests: all pass.
2026-10-18 20:10:39 -07:00

43 lines
1.3 KiB
C#

using Xunit;
namespace Server.Tests;
[Collection("Sequential Server Tests")]
public class LocalizationEntryTests
{
[Fact]
public void TestClilocAsParameter()
{
Localization.Add("enu", 500002, "This tests ~1_NUMBER~ as parameters.");
Localization.Add("enu", 500003, "clilocs");
string numericFormatter = Localization.Format(500002, "enu", $"{500003:#}");
string stringParam = Localization.Format(500002, "enu", $"{"#500003"}");
Assert.Equal("This tests clilocs as parameters.", numericFormatter);
Assert.Equal("This tests clilocs as parameters.", stringParam);
}
[Fact]
public void RemovingTheLastFallbackEntry_KeepsLaterAddsVisible()
{
Localization.Clear();
try
{
Localization.Add("enu", 500004, "first");
Assert.True(Localization.Remove("enu", 500004));
Localization.Add("enu", 500005, "second");
Assert.False(Localization.TryGetLocalization(500004, out _));
Assert.True(Localization.TryGetLocalization(500005, out var entry));
Assert.Equal("second", entry.Text);
}
finally
{
// Lets the next lookup reload the real tables from disk.
Localization.Clear();
}
}
}