-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into scoreinfo-suuuuuuuuuuuuuuuuuuuuuuuuuucks
- Loading branch information
Showing
8 changed files
with
242 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Threading.Tasks; | ||
using Moq; | ||
using osu.Game.Online.Multiplayer; | ||
using osu.Server.Spectator.Database; | ||
using osu.Server.Spectator.Database.Models; | ||
using Xunit; | ||
|
||
namespace osu.Server.Spectator.Tests | ||
{ | ||
public class ChatFiltersTest | ||
{ | ||
private readonly Mock<IDatabaseFactory> factoryMock; | ||
private readonly Mock<IDatabaseAccess> databaseMock; | ||
|
||
public ChatFiltersTest() | ||
{ | ||
factoryMock = new Mock<IDatabaseFactory>(); | ||
databaseMock = new Mock<IDatabaseAccess>(); | ||
|
||
factoryMock.Setup(factory => factory.GetInstance()).Returns(databaseMock.Object); | ||
} | ||
|
||
[Theory] | ||
[InlineData("bad phrase", "good phrase")] | ||
[InlineData("WHAT HAPPENS IF I SAY BAD THING IN CAPS", "WHAT HAPPENS IF I SAY good THING IN CAPS")] | ||
[InlineData("thing is bad", "thing is good")] | ||
[InlineData("look at this badness", "look at this goodness")] | ||
public async Task TestPlainFilterReplacement(string input, string expectedOutput) | ||
{ | ||
databaseMock.Setup(db => db.GetAllChatFiltersAsync()).ReturnsAsync([ | ||
new chat_filter { match = "bad", replacement = "good" }, | ||
new chat_filter { match = "fullword", replacement = "okay", whitespace_delimited = true }, | ||
new chat_filter { match = "absolutely forbidden", replacement = "", block = true } | ||
]); | ||
|
||
var filters = new ChatFilters(factoryMock.Object); | ||
|
||
Assert.Equal(expectedOutput, await filters.FilterAsync(input)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("fullword at the start", "okay at the start")] | ||
[InlineData("FULLWORD IN CAPS!!", "okay IN CAPS!!")] | ||
[InlineData("at the end is fullword", "at the end is okay")] | ||
[InlineData("middle is where the fullword is", "middle is where the okay is")] | ||
[InlineData("anotherfullword is not replaced", "anotherfullword is not replaced")] | ||
[InlineData("fullword fullword2", "okay great")] | ||
[InlineData("fullwordfullword2", "fullwordfullword2")] | ||
[InlineData("i do a delimiter/inside", "i do a nice try")] | ||
public async Task TestWhitespaceDelimitedFilterReplacement(string input, string expectedOutput) | ||
{ | ||
databaseMock.Setup(db => db.GetAllChatFiltersAsync()).ReturnsAsync([ | ||
new chat_filter { match = "bad", replacement = "good" }, | ||
new chat_filter { match = "fullword", replacement = "okay", whitespace_delimited = true }, | ||
new chat_filter { match = "fullword2", replacement = "great", whitespace_delimited = true }, | ||
new chat_filter { match = "delimiter/inside", replacement = "nice try", whitespace_delimited = true }, | ||
new chat_filter { match = "absolutely forbidden", replacement = "", block = true } | ||
]); | ||
|
||
var filters = new ChatFilters(factoryMock.Object); | ||
|
||
Assert.Equal(expectedOutput, await filters.FilterAsync(input)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("absolutely forbidden")] | ||
[InlineData("sPoNGeBoB SaYS aBSolUtElY FoRbIdDeN")] | ||
[InlineData("this is absolutely forbidden full stop!!!")] | ||
public async Task TestBlockingFilter(string input) | ||
{ | ||
databaseMock.Setup(db => db.GetAllChatFiltersAsync()).ReturnsAsync([ | ||
new chat_filter { match = "bad", replacement = "good" }, | ||
new chat_filter { match = "fullword", replacement = "okay", whitespace_delimited = true }, | ||
new chat_filter { match = "absolutely forbidden", replacement = "", block = true } | ||
]); | ||
|
||
var filters = new ChatFilters(factoryMock.Object); | ||
|
||
await Assert.ThrowsAsync<InvalidStateException>(() => filters.FilterAsync(input)); | ||
} | ||
|
||
[Fact] | ||
public async Task TestLackOfBlockingFilters() | ||
{ | ||
databaseMock.Setup(db => db.GetAllChatFiltersAsync()).ReturnsAsync([ | ||
new chat_filter { match = "bad", replacement = "good" }, | ||
new chat_filter { match = "fullword", replacement = "okay", whitespace_delimited = true }, | ||
]); | ||
|
||
var filters = new ChatFilters(factoryMock.Object); | ||
|
||
await filters.FilterAsync("this should be completely fine"); // should not throw | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.