mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using RadicadeServer.RecNet;
|
||||
using RadicadeServer.RecNet.Enums;
|
||||
using RadicadeServer.Utils;
|
||||
using Xunit;
|
||||
|
||||
namespace RadicadeServer.Tests;
|
||||
|
||||
public class StringToolsTests
|
||||
{
|
||||
[Fact]
|
||||
public void InvalidRoomTagDoesNotBreakRoomLists()
|
||||
{
|
||||
var tags = StringTools.ReadTags("rro,2|action");
|
||||
var tag = Assert.Single(tags);
|
||||
Assert.Equal("rro", tag.Tag);
|
||||
}
|
||||
|
||||
// Beta-enabled rooms (e.g. the imported Showdown room) carry a "beta" tag with
|
||||
// TagType.Auto - matching captured real RecNet responses - which is what flips
|
||||
// the client's "Allow Creative Tools Beta Content" room setting on. A round-trip
|
||||
// through the stored tag string must preserve it or the toggle stays greyed out.
|
||||
[Fact]
|
||||
public void BetaTag_SurvivesTagStringRoundTrip()
|
||||
{
|
||||
var stored = StringTools.CreateTagString(new List<ItemTag>
|
||||
{
|
||||
new ItemTag { Tag = "rro", Type = TagType.AGOnly },
|
||||
new ItemTag { Tag = "games", Type = TagType.General },
|
||||
new ItemTag { Tag = "beta", Type = TagType.Auto },
|
||||
});
|
||||
|
||||
Assert.Equal("rro,2|games,0|beta,1", stored);
|
||||
|
||||
var read = StringTools.ReadTags(stored);
|
||||
Assert.Equal(3, read.Count);
|
||||
var beta = read.Single(t => t.Tag == "beta");
|
||||
Assert.Equal(TagType.Auto, beta.Type);
|
||||
}
|
||||
|
||||
// The blacklisted words are the PATTERNS and the caller's text is the input. When
|
||||
// the arguments were the other way round, the player's own text was compiled as a
|
||||
// regex: anything with an unbalanced bracket or parenthesis threw an
|
||||
// ArgumentException straight out of the request (a bio of "Cute (" was enough), and
|
||||
// ordinary text stood a chance of being rejected as a false positive.
|
||||
[Theory]
|
||||
[InlineData("Cool person")]
|
||||
[InlineData("Cute (")]
|
||||
[InlineData("[unclosed")]
|
||||
[InlineData("a.b*c")]
|
||||
[InlineData("bob")]
|
||||
public void IsPure_AcceptsOrdinaryTextThatLooksLikeARegex(string text)
|
||||
{
|
||||
Assert.True(text.IsPure());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("nigger")]
|
||||
[InlineData("well, nigger123")]
|
||||
[InlineData("NIGGER")]
|
||||
[InlineData("a fag")]
|
||||
public void IsPure_RejectsTextContainingABlacklistedWord(string text)
|
||||
{
|
||||
Assert.False(text.IsPure());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Sanitize_MasksBlacklistedWordsRegardlessOfCase()
|
||||
{
|
||||
Assert.Equal("****", "Nigger".Sanitize());
|
||||
Assert.Equal("hello there", "hello there".Sanitize());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user