Skip to content
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 10 commits into from
Jul 4, 2024
235 changes: 235 additions & 0 deletions osu.Game.Tests/Editing/Checks/CheckTitleMarkersTest.cs
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));
}
Comment on lines +46 to +67
Copy link
Member

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).

Copy link
Collaborator

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.

Copy link
Member

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.


[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));
}
}
}
3 changes: 3 additions & 0 deletions osu.Game/Rulesets/Edit/BeatmapVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class BeatmapVerifier : IBeatmapVerifier

// Events
new CheckBreaks(),

// Metadata
new CheckTitleMarkers(),
};

public IEnumerable<Issue> Run(BeatmapVerifierContext context)
Expand Down
72 changes: 72 additions & 0 deletions osu.Game/Rulesets/Edit/Checks/CheckTitleMarkers.cs
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);
}
}
}
Loading