-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add verify checks for incorrect title markers #28716
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7cb3d74
Add verify checks for title markers
64ArthurAraujo 7cdad20
Fix explicit array type specification in MarkerChecks
64ArthurAraujo 7143ff5
Make `MarkerChecks` and `MarkerCheck` class private
64ArthurAraujo 21829e7
Fix test method names
64ArthurAraujo 901fec6
Address code quality issues
bdach 32b3d3d
Compile regexes for speed
bdach 5696e85
Adjust conditionals
bdach bcb479d
Use one less regex
bdach 00a0058
Fix typo
bdach 899c8d3
Merge branch 'master' into verify-title-markers
frenzibyte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,235 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Game.Beatmaps; | ||
using osu.Game.Rulesets.Edit; | ||
using osu.Game.Rulesets.Edit.Checks; | ||
using osu.Game.Rulesets.Objects; | ||
using osu.Game.Tests.Beatmaps; | ||
|
||
namespace osu.Game.Tests.Editing.Checks | ||
{ | ||
[TestFixture] | ||
public class CheckTitleMarkersTest | ||
{ | ||
private CheckTitleMarkers check = null!; | ||
|
||
private IBeatmap beatmap = null!; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
check = new CheckTitleMarkers(); | ||
|
||
beatmap = new Beatmap<HitObject> | ||
{ | ||
BeatmapInfo = new BeatmapInfo | ||
{ | ||
Metadata = new BeatmapMetadata | ||
{ | ||
Title = "Egao no Kanata", | ||
TitleUnicode = "エガオノカナタ" | ||
} | ||
} | ||
}; | ||
} | ||
|
||
[Test] | ||
public void TestNoTitleMarkers() | ||
{ | ||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
Assert.That(issues, Has.Count.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
public void TestTvSizeMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (TV Size)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (TV Size)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
public void TestMalformedTvSizeMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (tv size)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (tv size)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(2)); | ||
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker)); | ||
} | ||
|
||
[Test] | ||
public void TestGameVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (Game Ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Game Ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
public void TestMalformedGameVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (game ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (game ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(2)); | ||
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker)); | ||
} | ||
|
||
[Test] | ||
public void TestShortVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (Short Ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Short Ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
public void TestMalformedShortVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (short ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (short ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(2)); | ||
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker)); | ||
} | ||
|
||
[Test] | ||
public void TestCutVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (Cut Ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Cut Ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
public void TestMalformedCutVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (cut ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (cut ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(2)); | ||
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker)); | ||
} | ||
|
||
[Test] | ||
public void TestSpedUpVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (Sped Up Ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Sped Up Ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
public void TestMalformedSpedUpVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (sped up ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (sped up ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(2)); | ||
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker)); | ||
} | ||
|
||
[Test] | ||
public void TestNightcoreMixMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (Nightcore Mix)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Nightcore Mix)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
public void TestMalformedNightcoreMixMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (nightcore mix)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (nightcore mix)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(2)); | ||
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker)); | ||
} | ||
|
||
[Test] | ||
public void TestSpedUpCutVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (Sped Up & Cut Ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Sped Up & Cut Ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
public void TestMalformedSpedUpCutVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (sped up & cut ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (sped up & cut ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(2)); | ||
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker)); | ||
} | ||
|
||
[Test] | ||
public void TestNightcoreCutVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (Nightcore & Cut Ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Nightcore & Cut Ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
public void TestMalformedNightcoreCutVerMarker() | ||
{ | ||
beatmap.BeatmapInfo.Metadata.Title += " (nightcore & cut ver.)"; | ||
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (nightcore & cut ver.)"; | ||
|
||
var issues = check.Run(getContext(beatmap)).ToList(); | ||
|
||
Assert.That(issues, Has.Count.EqualTo(2)); | ||
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker)); | ||
} | ||
|
||
private BeatmapVerifierContext getContext(IBeatmap beatmap) | ||
{ | ||
return new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap)); | ||
} | ||
} | ||
} |
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
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,72 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Collections.Generic; | ||
using System.Text.RegularExpressions; | ||
using osu.Game.Rulesets.Edit.Checks.Components; | ||
|
||
namespace osu.Game.Rulesets.Edit.Checks | ||
{ | ||
public class CheckTitleMarkers : ICheck | ||
{ | ||
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Metadata, "Checks for incorrect formats of (TV Size) / (Game Ver.) / (Short Ver.) / (Cut Ver.) / (Sped Up Ver.) / etc in title."); | ||
|
||
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[] | ||
{ | ||
new IssueTemplateIncorrectMarker(this), | ||
}; | ||
|
||
private readonly IEnumerable<MarkerCheck> markerChecks = | ||
[ | ||
new MarkerCheck(@"(TV Size)", @"(?i)(tv (size|ver))"), | ||
new MarkerCheck(@"(Game Ver.)", @"(?i)(game (size|ver))"), | ||
new MarkerCheck(@"(Short Ver.)", @"(?i)(short (size|ver))"), | ||
new MarkerCheck(@"(Cut Ver.)", @"(?i)(?<!& )(cut (size|ver))"), | ||
new MarkerCheck(@"(Sped Up Ver.)", @"(?i)(?<!& )(sped|speed) ?up ver"), | ||
new MarkerCheck(@"(Nightcore Mix)", @"(?i)(?<!& )(nightcore|night core) (ver|mix)"), | ||
new MarkerCheck(@"(Sped Up & Cut Ver.)", @"(?i)(sped|speed) ?up (ver)? ?& cut (size|ver)"), | ||
new MarkerCheck(@"(Nightcore & Cut Ver.)", @"(?i)(nightcore|night core) (ver|mix)? ?& cut (size|ver)"), | ||
]; | ||
|
||
public IEnumerable<Issue> Run(BeatmapVerifierContext context) | ||
{ | ||
string romanisedTitle = context.Beatmap.Metadata.Title; | ||
string unicodeTitle = context.Beatmap.Metadata.TitleUnicode; | ||
|
||
foreach (var check in markerChecks) | ||
{ | ||
bool hasRomanisedTitle = unicodeTitle != romanisedTitle; | ||
|
||
if (check.AnyRegex.IsMatch(unicodeTitle) && !check.ExactRegex.IsMatch(unicodeTitle)) | ||
yield return new IssueTemplateIncorrectMarker(this).Create("Title", check.CorrectMarkerFormat); | ||
|
||
if (hasRomanisedTitle && check.AnyRegex.IsMatch(romanisedTitle) && !check.ExactRegex.IsMatch(romanisedTitle)) | ||
yield return new IssueTemplateIncorrectMarker(this).Create("Romanised title", check.CorrectMarkerFormat); | ||
} | ||
} | ||
|
||
private class MarkerCheck | ||
{ | ||
public readonly string CorrectMarkerFormat; | ||
public readonly Regex ExactRegex; | ||
public readonly Regex AnyRegex; | ||
|
||
public MarkerCheck(string exact, string anyRegex) | ||
{ | ||
CorrectMarkerFormat = exact; | ||
ExactRegex = new Regex(Regex.Escape(exact), RegexOptions.Compiled); | ||
frenzibyte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
AnyRegex = new Regex(anyRegex, RegexOptions.Compiled); | ||
} | ||
} | ||
|
||
public class IssueTemplateIncorrectMarker : IssueTemplate | ||
{ | ||
public IssueTemplateIncorrectMarker(ICheck check) | ||
: base(check, IssueType.Problem, "{0} field has a incorrect format of marker {1}") | ||
frenzibyte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
} | ||
|
||
public Issue Create(string titleField, string correctMarkerFormat) => new Issue(this, titleField, correctMarkerFormat); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are quite repetitive / useless, and they're not covering more important cases like different writings of the format (e.g.
(TV Ver.)
/(Game Size)
which are apparently deemed incorrect).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests being repetitive is never a big deal although these would take pretty well to parameterising.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I mentioned this because it was quite painful to add more useful tests than just the case-sensitivity ones.