feat: support long text and safe attachment batches
Build web service image / build (push) Successful in 1m15s
Build web service image / build (push) Successful in 1m15s
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using WxAgent.Core;
|
||||
using Xunit;
|
||||
|
||||
namespace WxAgent.Core.Tests;
|
||||
|
||||
public sealed class WechatTextInputSegmentationTests
|
||||
{
|
||||
[Fact]
|
||||
public void SplitForSendSplitsLongTextAtTheSingleMessageBoundary()
|
||||
{
|
||||
var text = new string('x', WechatTextInput.MaxSegmentLength + 1);
|
||||
|
||||
var segments = WechatTextInput.SplitForSend(text);
|
||||
|
||||
Assert.Equal(2, segments.Count);
|
||||
Assert.Equal(WechatTextInput.MaxSegmentLength, segments[0].Length);
|
||||
Assert.Equal(1, segments[1].Length);
|
||||
Assert.Equal(text, string.Concat(segments));
|
||||
Assert.Throws<WxAgentException>(() => WechatTextInput.Prepare(text));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SplitForSendDoesNotBreakACombiningTextElement()
|
||||
{
|
||||
var prefix = new string('x', WechatTextInput.MaxSegmentLength - 1);
|
||||
var combiningElement = "e\u0301";
|
||||
var text = prefix + combiningElement + "tail";
|
||||
|
||||
var segments = WechatTextInput.SplitForSend(text);
|
||||
|
||||
Assert.Equal(2, segments.Count);
|
||||
Assert.Equal(prefix, segments[0]);
|
||||
Assert.StartsWith(combiningElement, segments[1], StringComparison.Ordinal);
|
||||
Assert.All(segments, segment => Assert.InRange(segment.Length, 1, WechatTextInput.MaxSegmentLength));
|
||||
Assert.Equal(text, string.Concat(segments));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SplitForSendRejectsTextBeyondTheBoundedTotalLength()
|
||||
{
|
||||
var text = new string('x', WechatTextInput.MaxTextLength + 1);
|
||||
|
||||
var exception = Assert.Throws<WxAgentException>(() => WechatTextInput.SplitForSend(text));
|
||||
|
||||
Assert.Equal(WxAgentErrorCode.InvalidArgument, exception.Code);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user