132 lines
4.7 KiB
C#
132 lines
4.7 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using AibisDream.MiniGame.Language;
|
|
using AibisDream.Utility;
|
|
using NUnit.Framework;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.Localization;
|
|
|
|
namespace AibisDream.SystemEditor.Tests
|
|
{
|
|
public sealed class LocalizationContractTests
|
|
{
|
|
private const string ParticleProfilePath =
|
|
"Assets/GameContent/Feature_Huoshan/Expression/ExpressionParticleLanguageProfile.asset";
|
|
|
|
[Test]
|
|
public void LocaleMappings_ResolveSupportedCodesAndSystemLanguages()
|
|
{
|
|
var localeCases = new Dictionary<string, LocaleKind>
|
|
{
|
|
["ru"] = LocaleKind.Ru,
|
|
["ru-RU"] = LocaleKind.Ru,
|
|
["es"] = LocaleKind.Es,
|
|
["es-ES"] = LocaleKind.Es,
|
|
["pt"] = LocaleKind.PtBr,
|
|
["pt-BR"] = LocaleKind.PtBr
|
|
};
|
|
foreach (var pair in localeCases)
|
|
Assert.That(LocalizationKit.GetLocaleKind(pair.Key), Is.EqualTo(pair.Value), pair.Key);
|
|
|
|
Assert.That(LocalizationKit.MapSystemLanguage(SystemLanguage.Russian), Is.EqualTo("ru"));
|
|
Assert.That(LocalizationKit.MapSystemLanguage(SystemLanguage.Spanish), Is.EqualTo("es"));
|
|
Assert.That(LocalizationKit.MapSystemLanguage(SystemLanguage.Portuguese), Is.EqualTo("pt-BR"));
|
|
}
|
|
|
|
[Test]
|
|
public void UnknownCharacter_UsesItsKeyAsEveryLocalizedName()
|
|
{
|
|
var method = typeof(YarnUtil).GetMethod(
|
|
"GetCharacterVoByKey",
|
|
BindingFlags.Static | BindingFlags.NonPublic);
|
|
Assert.That(method, Is.Not.Null);
|
|
|
|
const string missingKey = "missing_character_contract_test";
|
|
var character = (CharacterVo)method.Invoke(null, new object[] { missingKey });
|
|
|
|
Assert.That(character.key, Is.EqualTo(missingKey));
|
|
Assert.That(
|
|
new[]
|
|
{
|
|
character.cn,
|
|
character.en,
|
|
character.ja,
|
|
character.ru,
|
|
character.es,
|
|
character.ptBr
|
|
},
|
|
Has.All.EqualTo(missingKey));
|
|
}
|
|
|
|
[Test]
|
|
public void CharacterCsv_ParsesExpandedLocaleColumns()
|
|
{
|
|
var characters = CsvUtil.ReadAsBean<Character>(Path.Combine(
|
|
Application.streamingAssetsPath,
|
|
"Config",
|
|
"character.csv"));
|
|
|
|
Assert.That(characters, Is.Not.Empty);
|
|
var peipei = characters.Single(character => character.Key == "peipei");
|
|
Assert.That(peipei.Ru, Is.Not.Null);
|
|
Assert.That(peipei.Es, Is.Not.Null);
|
|
Assert.That(peipei.PtBr, Is.Not.Null);
|
|
}
|
|
|
|
[Test]
|
|
public void ExpressionParsing_PreservesUnicodeAndWordBoundaries()
|
|
{
|
|
const string combining = "e\u0301";
|
|
Assert.That(
|
|
LanguageYarnCommand.TryParseExpressionPool(
|
|
$"中 中 あ {combining} 😀。",
|
|
out List<string> graphemePool),
|
|
Is.True);
|
|
Assert.That(
|
|
graphemePool,
|
|
Is.EqualTo(new[] { "中", "中", "あ", combining, "😀", "。" }));
|
|
|
|
Assert.That(
|
|
ExpressionTextTokenizer.TokenizeText(
|
|
"don't self-doubt ¿Por qué? веришь?",
|
|
ExpressionParticleUnitMode.Word),
|
|
Is.EqualTo(new[]
|
|
{
|
|
"don't",
|
|
"self-doubt",
|
|
"¿Por",
|
|
"qué?",
|
|
"веришь?"
|
|
}));
|
|
}
|
|
|
|
[Test]
|
|
public void ExpressionParticleProfile_MapsLanguageFamilies()
|
|
{
|
|
var profile = AssetDatabase.LoadAssetAtPath<ExpressionParticleLanguageProfile>(
|
|
ParticleProfilePath);
|
|
Assert.That(profile, Is.Not.Null);
|
|
Assert.That(profile.GetValidationErrors(), Is.Empty);
|
|
|
|
Assert.That(
|
|
profile.Resolve(new LocaleIdentifier("zh-Hans")).UnitMode,
|
|
Is.EqualTo(ExpressionParticleUnitMode.Grapheme));
|
|
Assert.That(
|
|
profile.Resolve(new LocaleIdentifier("ja-JP")).UnitMode,
|
|
Is.EqualTo(ExpressionParticleUnitMode.Grapheme));
|
|
foreach (var localeCode in new[] { "en", "es", "ru", "pt-BR" })
|
|
{
|
|
Assert.That(
|
|
profile.Resolve(new LocaleIdentifier(localeCode)).UnitMode,
|
|
Is.EqualTo(ExpressionParticleUnitMode.Word),
|
|
localeCode);
|
|
}
|
|
}
|
|
}
|
|
}
|