124 lines
4.3 KiB
C#
124 lines
4.3 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 AutoNextMetadataTests
|
|
{
|
|
[Test]
|
|
public void AutoNextWithoutParameter_UsesExistingFixedDelay()
|
|
{
|
|
var lineInfo = LineInfo.Generate(CreateLine("auto_next"));
|
|
|
|
Assert.That(lineInfo.isAutoSkip, Is.True);
|
|
Assert.That(lineInfo.autoNextDelaySeconds, Is.Null);
|
|
Assert.That(lineInfo.CalcAutoNextDelayTime(), Is.EqualTo(ConstRef.FixedDelay));
|
|
}
|
|
|
|
[Test]
|
|
public void AutoNextWithParameter_UsesSpecifiedSeconds()
|
|
{
|
|
var lineInfo = LineInfo.Generate(CreateLine("auto_next:4.5"));
|
|
|
|
Assert.That(lineInfo.isAutoSkip, Is.True);
|
|
Assert.That(lineInfo.autoNextDelaySeconds, Is.EqualTo(4.5f));
|
|
Assert.That(lineInfo.CalcAutoNextDelayTime(), Is.EqualTo(4500));
|
|
}
|
|
|
|
[Test]
|
|
public void AutoNextWithZeroDelay_IsValid()
|
|
{
|
|
var lineInfo = LineInfo.Generate(CreateLine("auto_next:0"));
|
|
|
|
Assert.That(lineInfo.isAutoSkip, Is.True);
|
|
Assert.That(lineInfo.autoNextDelaySeconds, Is.EqualTo(0f));
|
|
Assert.That(lineInfo.CalcAutoNextDelayTime(), Is.Zero);
|
|
}
|
|
|
|
[Test]
|
|
public void AutoNextParameter_UsesInvariantCulture()
|
|
{
|
|
var originalCulture = CultureInfo.CurrentCulture;
|
|
try
|
|
{
|
|
CultureInfo.CurrentCulture = new CultureInfo("de-DE");
|
|
var lineInfo = LineInfo.Generate(CreateLine("auto_next:4.5"));
|
|
|
|
Assert.That(lineInfo.autoNextDelaySeconds, Is.EqualTo(4.5f));
|
|
Assert.That(lineInfo.CalcAutoNextDelayTime(), Is.EqualTo(4500));
|
|
}
|
|
finally
|
|
{
|
|
CultureInfo.CurrentCulture = originalCulture;
|
|
}
|
|
}
|
|
|
|
[TestCase("auto_next:")]
|
|
[TestCase("auto_next:abc")]
|
|
[TestCase("auto_next:-1")]
|
|
[TestCase("auto_next:NaN")]
|
|
[TestCase("auto_next:Infinity")]
|
|
[TestCase("auto_next:2147484")]
|
|
public void AutoNextWithInvalidParameter_FallsBackToExistingFixedDelay(string metadata)
|
|
{
|
|
LogAssert.Expect(LogType.Warning, new Regex("auto_next 参数无效"));
|
|
|
|
var lineInfo = LineInfo.Generate(CreateLine(metadata));
|
|
|
|
Assert.That(lineInfo.isAutoSkip, Is.True);
|
|
Assert.That(lineInfo.autoNextDelaySeconds, Is.Null);
|
|
Assert.That(lineInfo.CalcAutoNextDelayTime(), Is.EqualTo(ConstRef.FixedDelay));
|
|
}
|
|
|
|
[TestCase("auto_next_extra")]
|
|
[TestCase("auto_next_extra:4.5")]
|
|
[TestCase("AUTO_NEXT")]
|
|
[TestCase("AUTO_NEXT:4.5")]
|
|
public void SimilarMetadata_IsNotRecognized(string metadata)
|
|
{
|
|
var line = CreateLine(metadata);
|
|
|
|
Assert.That(line.IsAutoSkipLine(), Is.False);
|
|
Assert.That(line.TryGetAutoNextDelaySeconds(out _), Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void ParameterizedTag_TakesPrecedenceOverPlainTag()
|
|
{
|
|
var lineInfo = LineInfo.Generate(CreateLine("auto_next", "auto_next:2.5"));
|
|
|
|
Assert.That(lineInfo.isAutoSkip, Is.True);
|
|
Assert.That(lineInfo.autoNextDelaySeconds, Is.EqualTo(2.5f));
|
|
Assert.That(lineInfo.CalcAutoNextDelayTime(), Is.EqualTo(2500));
|
|
}
|
|
|
|
[Test]
|
|
public void MultipleParameterizedTags_UseFirstAndWarn()
|
|
{
|
|
LogAssert.Expect(LogType.Warning, new Regex("存在多个 auto_next 参数标签"));
|
|
|
|
var lineInfo = LineInfo.Generate(CreateLine("auto_next:2.5", "auto_next:4.5"));
|
|
|
|
Assert.That(lineInfo.autoNextDelaySeconds, Is.EqualTo(2.5f));
|
|
Assert.That(lineInfo.CalcAutoNextDelayTime(), Is.EqualTo(2500));
|
|
}
|
|
|
|
private static LocalizedLine CreateLine(params string[] metadata)
|
|
{
|
|
return new LocalizedLine
|
|
{
|
|
TextID = "line:auto-next-test",
|
|
Metadata = metadata,
|
|
Text = new MarkupParseResult("Test line", new List<MarkupAttribute>())
|
|
};
|
|
}
|
|
}
|
|
}
|