Files
aibis-dream/Assets/Editor/Tests/YarnLineMetadataTests.cs

76 lines
2.8 KiB
C#

using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using AibisDream.Utility;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Yarn.Markup;
using Yarn.Unity;
namespace AibisDream.SystemEditor.Tests
{
public sealed class YarnLineMetadataTests
{
[Test]
public void AutoNext_UsesDefaultOrInvariantParameterizedDelay()
{
var plain = LineInfo.Generate(CreateLine("auto_next"));
Assert.That(plain.isAutoSkip, Is.True);
Assert.That(plain.CalcAutoNextDelayTime(), Is.EqualTo(ConstRef.FixedDelay));
var originalCulture = CultureInfo.CurrentCulture;
try
{
CultureInfo.CurrentCulture = new CultureInfo("de-DE");
var parameterized = LineInfo.Generate(CreateLine("auto_next:4.5"));
Assert.That(parameterized.isAutoSkip, Is.True);
Assert.That(parameterized.autoNextDelaySeconds, Is.EqualTo(4.5f));
Assert.That(parameterized.CalcAutoNextDelayTime(), Is.EqualTo(4500));
}
finally
{
CultureInfo.CurrentCulture = originalCulture;
}
}
[Test]
public void AutoNext_InvalidValueFallsBackAndSimilarTagIsIgnored()
{
LogAssert.Expect(LogType.Warning, new Regex("auto_next 参数无效"));
var invalid = LineInfo.Generate(CreateLine("auto_next:abc"));
Assert.That(invalid.isAutoSkip, Is.True);
Assert.That(invalid.autoNextDelaySeconds, Is.Null);
Assert.That(invalid.CalcAutoNextDelayTime(), Is.EqualTo(ConstRef.FixedDelay));
var similar = CreateLine("AUTO_NEXT", "auto_next_extra:4.5");
Assert.That(similar.IsAutoSkipLine(), Is.False);
Assert.That(similar.TryGetAutoNextDelaySeconds(out _), Is.False);
}
[Test]
public void OptionPrompt_RequiresExactMetadataTag()
{
Assert.That(CreateLine(YarnUtil.OptionPrompt).IsOptionPromptLine(), Is.True);
Assert.That(CreateLine("OPTION_PROMPT").IsOptionPromptLine(), Is.False);
Assert.That(CreateLine("option_prompts").IsOptionPromptLine(), Is.False);
Assert.That(
new LocalizedLine { Metadata = null }.IsOptionPromptLine(),
Is.False);
}
private static LocalizedLine CreateLine(params string[] metadata)
{
return new LocalizedLine
{
TextID = "line:yarn-metadata-contract",
Metadata = metadata,
Text = new MarkupParseResult(
"Test line",
new List<MarkupAttribute>())
};
}
}
}