From c8ae6e6809e98f660e103a42202863ecf520df02 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 11 Oct 2026 21:18:05 +0900 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E8=A8=80=E3=81=AE=E8=A9=A6=E9=A8=93?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpectrumColorShift.Tests/TextsTests.cs | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 SpectrumColorShift.Tests/TextsTests.cs diff --git a/SpectrumColorShift.Tests/TextsTests.cs b/SpectrumColorShift.Tests/TextsTests.cs new file mode 100644 index 0000000..c2c3a8b --- /dev/null +++ b/SpectrumColorShift.Tests/TextsTests.cs @@ -0,0 +1,60 @@ +using System.Collections; +using System.Globalization; +using System.Reflection; + +namespace SpectrumColorShift.Tests; + +public sealed class TextsTests +{ + public static readonly TheoryData Cultures = ["ja-JP", "en-US", "zh-CN", "zh-TW", "ko-KR", "es-ES", "ar-SA", "id-ID"]; + + static readonly string[] Keys = typeof(Texts) + .GetProperties(BindingFlags.Public | BindingFlags.Static) + .Where(property => property.PropertyType == typeof(string) && property.Name != nameof(Texts.CurrentCulture)) + .Select(property => property.Name) + .ToArray(); + + [Fact] + public void EveryLocalizedKeyHasAProperty() + { + var resources = Texts.ResourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, false)!; + var keys = resources.Cast().Select(entry => (string)entry.Key).Where(key => key != nameof(Texts.CurrentCulture)); + + Assert.Equal(keys.Order(), Keys.Order()); + } + + [Theory] + [MemberData(nameof(Cultures))] + public void EveryKeyIsTranslated(string culture) + { + var cultureInfo = CultureInfo.GetCultureInfo(culture); + + Assert.All(Keys, key => Assert.False(string.IsNullOrWhiteSpace(Texts.ResourceManager.GetString(key, cultureInfo)), key)); + } + + [Theory] + [MemberData(nameof(Cultures))] + public void EveryCultureCarriesItsOwnTranslations(string culture) + { + var cultureInfo = CultureInfo.GetCultureInfo(culture); + + Assert.Equal(culture.ToLowerInvariant(), Texts.ResourceManager.GetString(nameof(Texts.CurrentCulture), cultureInfo)); + } + + [Fact] + public void JapaneseIsTheNeutralLanguage() + { + var neutral = Texts.ResourceManager.GetString(nameof(Texts.SpectrumColorShift), CultureInfo.InvariantCulture); + + Assert.Equal("色ずれ(スペクトラム)", neutral); + Assert.Equal(neutral, Texts.ResourceManager.GetString(nameof(Texts.SpectrumColorShift), CultureInfo.GetCultureInfo("ja-JP"))); + } + + [Fact] + public void TheUpdateMessageEmbedsTheVersion() + { + var message = string.Format(CultureInfo.InvariantCulture, Texts.ResourceManager.GetString(nameof(Texts.UpdateAvailableMessage), CultureInfo.InvariantCulture)!, "v1.2.3"); + + Assert.Contains("v1.2.3", message); + } +}