mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +08:00
Add better channel test cases (testing non-existent channels)
This commit is contained in:
parent
d81d884a01
commit
e5188fd151
@ -14,6 +14,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual
|
namespace osu.Game.Tests.Visual
|
||||||
{
|
{
|
||||||
@ -32,6 +33,9 @@ namespace osu.Game.Tests.Visual
|
|||||||
typeof(MessageFormatter)
|
typeof(MessageFormatter)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private DependencyContainer dependencies;
|
||||||
|
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(parent);
|
||||||
|
|
||||||
public TestCaseChatLink()
|
public TestCaseChatLink()
|
||||||
{
|
{
|
||||||
Add(textContainer = new TestChatLineContainer
|
Add(textContainer = new TestChatLineContainer
|
||||||
@ -41,6 +45,20 @@ namespace osu.Game.Tests.Visual
|
|||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colours)
|
||||||
|
{
|
||||||
|
linkColour = colours.Blue;
|
||||||
|
dependencies.Cache(new ChatOverlay
|
||||||
|
{
|
||||||
|
AvailableChannels =
|
||||||
|
{
|
||||||
|
new Channel { Name = "#english" },
|
||||||
|
new Channel { Name = "#japanese" }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
testLinksGeneral();
|
testLinksGeneral();
|
||||||
testEcho();
|
testEcho();
|
||||||
@ -111,11 +129,12 @@ namespace osu.Game.Tests.Visual
|
|||||||
addMessageWithChecks("I am important!", 0, false, true);
|
addMessageWithChecks("I am important!", 0, false, true);
|
||||||
addMessageWithChecks("feels important", 0, true, true);
|
addMessageWithChecks("feels important", 0, true, true);
|
||||||
addMessageWithChecks("likes to post this [https://osu.ppy.sh/home link].", 1, true, true, expectedActions: LinkAction.External);
|
addMessageWithChecks("likes to post this [https://osu.ppy.sh/home link].", 1, true, true, expectedActions: LinkAction.External);
|
||||||
addMessageWithChecks("Join my multiplayer game osump://12346.",1, expectedActions: LinkAction.JoinMultiplayerMatch);
|
addMessageWithChecks("Join my multiplayer game osump://12346.", 1, expectedActions: LinkAction.JoinMultiplayerMatch);
|
||||||
addMessageWithChecks("Join my [multiplayer game](osump://12346).", 1, expectedActions: LinkAction.JoinMultiplayerMatch);
|
addMessageWithChecks("Join my [multiplayer game](osump://12346).", 1, expectedActions: LinkAction.JoinMultiplayerMatch);
|
||||||
addMessageWithChecks("Join my [#english](osu://chan/english).", 1, expectedActions: LinkAction.OpenChannel);
|
addMessageWithChecks("Join my [#english](osu://chan/#english).", 1, expectedActions: LinkAction.OpenChannel);
|
||||||
addMessageWithChecks("Join my osu://chan/#english.", 1, expectedActions: LinkAction.OpenChannel);
|
addMessageWithChecks("Join my osu://chan/#english.", 1, expectedActions: LinkAction.OpenChannel);
|
||||||
addMessageWithChecks("Join my #english or #japanese channels.", 2, expectedActions: new [] { LinkAction.OpenChannel, LinkAction.OpenChannel });
|
addMessageWithChecks("Join my #english or #japanese channels.", 2, expectedActions: new[] { LinkAction.OpenChannel, LinkAction.OpenChannel });
|
||||||
|
addMessageWithChecks("Join my #english or #nonexistent #hashtag channels.", 1, expectedActions: LinkAction.OpenChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testEcho()
|
private void testEcho()
|
||||||
@ -141,12 +160,6 @@ namespace osu.Game.Tests.Visual
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuColour colours)
|
|
||||||
{
|
|
||||||
linkColour = colours.Blue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DummyEchoMessage : LocalEchoMessage
|
private class DummyEchoMessage : LocalEchoMessage
|
||||||
{
|
{
|
||||||
public DummyEchoMessage(string text)
|
public DummyEchoMessage(string text)
|
||||||
@ -160,6 +173,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
private class DummyMessage : Message
|
private class DummyMessage : Message
|
||||||
{
|
{
|
||||||
private static long messageCounter;
|
private static long messageCounter;
|
||||||
|
|
||||||
internal static readonly User TEST_SENDER_BACKGROUND = new User
|
internal static readonly User TEST_SENDER_BACKGROUND = new User
|
||||||
{
|
{
|
||||||
Username = @"i-am-important",
|
Username = @"i-am-important",
|
||||||
|
@ -43,7 +43,7 @@ namespace osu.Game.Online.Chat
|
|||||||
private static readonly Regex time_regex = new Regex(@"\d\d:\d\d:\d\d\d? [^-]*");
|
private static readonly Regex time_regex = new Regex(@"\d\d:\d\d:\d\d\d? [^-]*");
|
||||||
|
|
||||||
// #osu
|
// #osu
|
||||||
private static readonly Regex channel_regex = new Regex(@"#[a-zA-Z]+[a-zA-Z0-9]+");
|
private static readonly Regex channel_regex = new Regex(@"(#[a-zA-Z]+[a-zA-Z0-9]+)");
|
||||||
|
|
||||||
// Unicode emojis
|
// Unicode emojis
|
||||||
private static readonly Regex emoji_regex = new Regex(@"(\uD83D[\uDC00-\uDE4F])");
|
private static readonly Regex emoji_regex = new Regex(@"(\uD83D[\uDC00-\uDE4F])");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -225,7 +226,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
username.Text = $@"{message.Sender.Username}" + (senderHasBackground || message.IsAction ? "" : ":");
|
username.Text = $@"{message.Sender.Username}" + (senderHasBackground || message.IsAction ? "" : ":");
|
||||||
|
|
||||||
// remove non-existent channels from the link list
|
// remove non-existent channels from the link list
|
||||||
message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chat?.AvailableChannels.TrueForAll(c => c.Name != link.Argument) != false);
|
message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chat?.AvailableChannels.Any(c => c.Name == link.Argument) != true);
|
||||||
|
|
||||||
contentFlow.Clear();
|
contentFlow.Clear();
|
||||||
contentFlow.AddLinks(message.DisplayContent, message.Links);
|
contentFlow.AddLinks(message.DisplayContent, message.Links);
|
||||||
|
Loading…
Reference in New Issue
Block a user