98 lines
3.1 KiB
C#
98 lines
3.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using AibisDream.EditorTools.Localization;
|
|
using AibisDream.UI;
|
|
using NUnit.Framework;
|
|
|
|
namespace AibisDream.SystemEditor.Tests
|
|
{
|
|
public sealed class LocalizedObjSpriteTests
|
|
{
|
|
private string temporaryRoot;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
temporaryRoot = Path.Combine(
|
|
Path.GetTempPath(),
|
|
"AibisDreamLocalizedObjSpriteTests",
|
|
Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(temporaryRoot);
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
if (!string.IsNullOrEmpty(temporaryRoot) && Directory.Exists(temporaryRoot))
|
|
Directory.Delete(temporaryRoot, true);
|
|
}
|
|
|
|
[TestCase("zh-Hans", "病历")]
|
|
[TestCase("zh-CN", "病历")]
|
|
[TestCase("en", "病历-en")]
|
|
[TestCase("en-US", "病历-en")]
|
|
[TestCase("ja-JP", "病历-ja-JP")]
|
|
[TestCase("ru-RU", "病历-ru")]
|
|
[TestCase("es-ES", "病历-es")]
|
|
[TestCase("pt-BR", "病历-pt-BR")]
|
|
public void GetPicName_UsesCanonicalLocaleSuffix(
|
|
string localeCode,
|
|
string expected)
|
|
{
|
|
Assert.That(
|
|
LocalizedObjSpriteNaming.GetPicName("病历.png", localeCode),
|
|
Is.EqualTo(expected));
|
|
}
|
|
|
|
[Test]
|
|
public void CandidateNames_FallBackToUnsuffixedChineseWithoutDuplicates()
|
|
{
|
|
Assert.That(
|
|
LocalizedObjSpriteNaming.GetCandidatePicNames("病历.png", "en"),
|
|
Is.EqualTo(new[] { "病历-en", "病历" }));
|
|
Assert.That(
|
|
LocalizedObjSpriteNaming.GetCandidatePicNames("病历.png", "zh-Hans"),
|
|
Is.EqualTo(new[] { "病历" }));
|
|
}
|
|
|
|
[Test]
|
|
public void Validator_IgnoresUnsuffixedOnlySprites()
|
|
{
|
|
WriteSprite("普通图片.png");
|
|
|
|
Assert.That(
|
|
LocalizedObjSpriteValidator.Validate(temporaryRoot),
|
|
Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void Validator_RequiresEveryVariantAfterAGroupIsDetected()
|
|
{
|
|
WriteCompleteGroup("病历");
|
|
Assert.That(
|
|
LocalizedObjSpriteValidator.Validate(temporaryRoot),
|
|
Is.Empty);
|
|
|
|
File.Delete(Path.Combine(temporaryRoot, "病历-ru.png"));
|
|
var issues = LocalizedObjSpriteValidator.Validate(temporaryRoot);
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
Assert.That(issues.Single().AssetPath, Does.EndWith("病历-ru.png"));
|
|
Assert.That(issues.Single().Message, Does.Contain("'ru'"));
|
|
}
|
|
|
|
private void WriteCompleteGroup(string logicalName)
|
|
{
|
|
WriteSprite($"{logicalName}.png");
|
|
foreach (string localeCode in LocalizedObjSpriteNaming.NonDefaultLocaleCodes)
|
|
WriteSprite($"{logicalName}-{localeCode}.png");
|
|
}
|
|
|
|
private void WriteSprite(string fileName)
|
|
{
|
|
File.WriteAllBytes(Path.Combine(temporaryRoot, fileName), Array.Empty<byte>());
|
|
}
|
|
}
|
|
}
|