79 lines
2.7 KiB
C#
79 lines
2.7 KiB
C#
using AcDream.Core.Chat;
|
|
|
|
namespace AcDream.Core.Tests.Chat;
|
|
|
|
/// <summary>
|
|
/// Phase J: <see cref="ChatLog.SetLocalPlayerGuid"/> teaches the log
|
|
/// to recognize ACE's HearSpeech echo of the local player's own /say
|
|
/// — the server broadcasts to all in range INCLUDING the sender, so
|
|
/// we'd otherwise see both our optimistic "You say" and the
|
|
/// third-person "+Acdream says" from the server. Substituting the
|
|
/// sender to "" routes through the formatter's IsOwnSpeaker path so
|
|
/// only the singular first-person line shows.
|
|
/// </summary>
|
|
public sealed class ChatLogLocalGuidTests
|
|
{
|
|
[Fact]
|
|
public void OnLocalSpeech_OwnGuidMatch_SubstitutesYou()
|
|
{
|
|
var log = new ChatLog();
|
|
log.SetLocalPlayerGuid(0x5000_000A);
|
|
|
|
log.OnLocalSpeech("+Acdream", "hello world",
|
|
senderGuid: 0x5000_000A, isRanged: false);
|
|
|
|
var entry = log.Snapshot()[0];
|
|
Assert.Equal(ChatKind.LocalSpeech, entry.Kind);
|
|
Assert.Equal("You", entry.Sender);
|
|
Assert.Equal("hello world", entry.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void OnLocalSpeech_DifferentGuid_KeepsSenderName()
|
|
{
|
|
var log = new ChatLog();
|
|
log.SetLocalPlayerGuid(0x5000_000A);
|
|
|
|
log.OnLocalSpeech("Caith", "hi",
|
|
senderGuid: 0x5000_0042, isRanged: false);
|
|
|
|
Assert.Equal("Caith", log.Snapshot()[0].Sender);
|
|
}
|
|
|
|
[Fact]
|
|
public void OnLocalSpeech_NoLocalGuidSet_FallsBackToEmptySubstitution()
|
|
{
|
|
// Pre-login (guid not yet known), the existing empty-sender
|
|
// substitution still applies — server-driven ranged echoes
|
|
// arrive with sender="" before the player has a guid.
|
|
var log = new ChatLog();
|
|
log.OnLocalSpeech("", "anyone home?",
|
|
senderGuid: 0u, isRanged: true);
|
|
|
|
Assert.Equal("You", log.Snapshot()[0].Sender);
|
|
Assert.Equal(ChatKind.RangedSpeech, log.Snapshot()[0].Kind);
|
|
}
|
|
|
|
[Fact]
|
|
public void ResetSessionIdentity_RetainsTranscriptButClearsGuidAndDedupeWindow()
|
|
{
|
|
var log = new ChatLog();
|
|
const uint oldGuid = 0x50000001u;
|
|
const uint newGuid = 0x50000002u;
|
|
log.SetLocalPlayerGuid(oldGuid);
|
|
log.OnSystemMessage("session boundary", 1u);
|
|
log.OnLocalSpeech("Old", "before", oldGuid, isRanged: false);
|
|
|
|
log.ResetSessionIdentity();
|
|
log.OnSystemMessage("session boundary", 1u);
|
|
log.OnLocalSpeech("Old", "after", oldGuid, isRanged: false);
|
|
log.SetLocalPlayerGuid(newGuid);
|
|
log.OnLocalSpeech("New", "new", newGuid, isRanged: false);
|
|
|
|
ChatEntry[] entries = log.Snapshot();
|
|
Assert.Equal(5, entries.Length);
|
|
Assert.Equal("You", entries[1].Sender);
|
|
Assert.Equal("Old", entries[3].Sender);
|
|
Assert.Equal("You", entries[4].Sender);
|
|
}
|
|
}
|