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

Separate the auto-generate logic in the LyricAutoGenerateChangeHandler. #1958

Merged

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,44 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics;

public partial class LyricLanguageChangeHandlerTest : LyricPropertyChangeHandlerTest<LyricLanguageChangeHandler>
{
protected override bool IncludeAutoGenerator => true;

#region Auto-Generate

[Test]
public void TestDetectLanguage()
{
PrepareHitObject(() => new Lyric
{
Text = "カラオケ"
});

TriggerHandlerChanged(c => c.AutoGenerate());

AssertSelectedHitObject(h =>
{
Assert.AreEqual(new CultureInfo("ja"), h.Language);
});
}

[Test]
public void TestDetectLanguageWithNonSupportedLyric()
{
PrepareHitObject(() => new Lyric
{
Text = "???"
});

TriggerHandlerChanged(c => c.AutoGenerate());

AssertSelectedHitObject(h =>
{
Assert.IsNull(h.Language);
});
}

#endregion

[Test]
public void TestSetLanguageToJapanese()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Generator;
using osu.Game.Rulesets.Karaoke.Edit.Utils;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Screens.Edit;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics;

public partial class LyricNotesChangeHandlerTest : LyricPropertyChangeHandlerTest<LyricNotesChangeHandler>
{
protected override bool IncludeAutoGenerator => true;

#region Note

[Test]
public void TestAutoGenerateNotes()
{
PrepareHitObject(() => new Lyric
{
Text = "カラオケ",
TimeTags = new[]
{
new TimeTag(new TextIndex(0), 0),
new TimeTag(new TextIndex(1), 1000),
new TimeTag(new TextIndex(2), 2000),
new TimeTag(new TextIndex(3), 3000),
new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 4000),
}
});

TriggerHandlerChanged(c => c.AutoGenerate());

AssertSelectedHitObject(h =>
{
var actualNotes = getMatchedNotes(h);
Assert.AreEqual(4, actualNotes.Length);

Assert.AreEqual("カ", actualNotes[0].Text);
Assert.AreEqual("ラ", actualNotes[1].Text);
Assert.AreEqual("オ", actualNotes[2].Text);
Assert.AreEqual("ケ", actualNotes[3].Text);
});
}

[Test]
public void TestAutoGenerateNotesWithNonSupportedLyric()
{
PrepareHitObject(() => new Lyric
{
Text = "カラオケ",
});

TriggerHandlerChangedWithException<GeneratorNotSupportedException>(c => c.AutoGenerate());
}

private Note[] getMatchedNotes(Lyric lyric)
{
var editorBeatmap = Dependencies.Get<EditorBeatmap>();
return EditorBeatmapUtils.GetNotesByLyric(editorBeatmap, lyric).ToArray();
}

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Globalization;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics;

/// <summary>
/// This test is focus on make sure that:
/// If the <see cref="Lyric.ReferenceLyric"/> in the <see cref="Lyric"/> is not empty.
/// <see cref="ILyricPropertyAutoGenerateChangeHandler"/> should be able to change the property.
/// </summary>
/// <typeparam name="TChangeHandler"></typeparam>
[TestFixture(typeof(LyricReferenceChangeHandler))]
[TestFixture(typeof(LyricLanguageChangeHandler))]
[TestFixture(typeof(LyricRubyTagsChangeHandler))]
[TestFixture(typeof(LyricRomajiTagsChangeHandler))]
[TestFixture(typeof(LyricTimeTagsChangeHandler))]
[TestFixture(typeof(LyricNotesChangeHandler))]
public partial class LyricPropertyAutoGenerateChangeHandlerTest<TChangeHandler> : LyricPropertyChangeHandlerTest<TChangeHandler>
where TChangeHandler : LyricPropertyChangeHandler, ILyricPropertyAutoGenerateChangeHandler, new()
{
protected override bool IncludeAutoGenerator => true;

# region With reference lyric

[Test]
public void TestCanGenerateWithReferenceLyric()
{
bool lyricReferenceChangeHandler = isLyricReferenceChangeHandler();

if (lyricReferenceChangeHandler)
{
PrepareHitObject(() => new Lyric
{
Text = "karaoke"
}, false);
}

PrepareLyricWithSyncConfig(new Lyric
{
Text = "karaoke",
Language = new CultureInfo(17), // for auto-generate ruby and romaji.
TimeTags = new[] // for auto-generate notes.
{
new TimeTag(new TextIndex(0), 0),
new TimeTag(new TextIndex(1), 1000),
new TimeTag(new TextIndex(2), 2000),
new TimeTag(new TextIndex(3), 3000),
new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 4000),
}
});

TriggerHandlerChanged(c =>
{
Assert.AreEqual(lyricReferenceChangeHandler, c.CanGenerate());
});
}

[Test]
public void TestGeneratorNotSupportedLyricsWithReferenceLyric()
{
bool lyricReferenceChangeHandler = isLyricReferenceChangeHandler();

if (lyricReferenceChangeHandler)
{
PrepareHitObject(() => new Lyric
{
Text = "karaoke"
}, false);
}

PrepareLyricWithSyncConfig(new Lyric
{
Text = "karaoke",
Language = new CultureInfo(17), // for auto-generate ruby and romaji.
TimeTags = new[] // for auto-generate notes.
{
new TimeTag(new TextIndex(0), 0),
new TimeTag(new TextIndex(1), 1000),
new TimeTag(new TextIndex(2), 2000),
new TimeTag(new TextIndex(3), 3000),
new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 4000),
}
});

TriggerHandlerChanged(c =>
{
bool hasNotSupportedLyrics = c.GetGeneratorNotSupportedLyrics().Any();
Assert.AreEqual(lyricReferenceChangeHandler, !hasNotSupportedLyrics);
});
}

[Test]
public void TestAutoGenerate()
{
bool lyricReferenceChangeHandler = isLyricReferenceChangeHandler();

if (lyricReferenceChangeHandler)
{
PrepareHitObject(() => new Lyric
{
Text = "karaoke"
}, false);
}

PrepareLyricWithSyncConfig(new Lyric
{
Text = "karaoke",
Language = new CultureInfo(17), // for auto-generate ruby and romaji.
TimeTags = new[] // for auto-generate notes.
{
new TimeTag(new TextIndex(0), 0),
new TimeTag(new TextIndex(1), 1000),
new TimeTag(new TextIndex(2), 2000),
new TimeTag(new TextIndex(3), 3000),
new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 4000),
}
});

if (lyricReferenceChangeHandler)
{
TriggerHandlerChanged(c => c.AutoGenerate());
}
else
{
TriggerHandlerChangedWithChangeForbiddenException(c => c.AutoGenerate());
}
}

private bool isLyricReferenceChangeHandler()
=> typeof(TChangeHandler) == typeof(LyricReferenceChangeHandler);

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,58 @@

using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Generator;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Objects.Properties;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics;

public partial class LyricReferenceChangeHandlerTest : LyricPropertyChangeHandlerTest<LyricReferenceChangeHandler>
{
protected override bool IncludeAutoGenerator => true;

#region Auto-Generate

[Test]
public void TestDetectReferenceLyric()
{
PrepareHitObject(() => new Lyric
{
Text = "カラオケ"
}, false);

PrepareHitObject(() => new Lyric
{
Text = "カラオケ"
});

TriggerHandlerChanged(c => c.AutoGenerate());

AssertSelectedHitObject(h =>
{
Assert.IsNotNull(h.ReferenceLyric);
Assert.IsTrue(h.ReferenceLyricConfig is SyncLyricConfig);
});
}

[Test]
public void TestDetectReferenceLyricWithNonSupportedLyric()
{
PrepareHitObject(() => new Lyric
{
Text = "カラオケ"
}, false);

PrepareHitObject(() => new Lyric
{
Text = "???"
});

TriggerHandlerChangedWithException<DetectorNotSupportedException>(c => c.AutoGenerate());
}

#endregion

[Test]
public void TestUpdateReferenceLyric()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,61 @@
using System.Globalization;
using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Generator;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics;

public partial class LyricRomajiTagsChangeHandlerTest : LyricPropertyChangeHandlerTest<LyricRomajiTagsChangeHandler>
{
protected override bool IncludeAutoGenerator => true;

#region Auto-Generate

[Test]
public void TestAutoGenerateRomajiTags()
{
PrepareHitObject(() => new Lyric
{
Text = "風",
Language = new CultureInfo(17)
});

TriggerHandlerChanged(c => c.AutoGenerate());

AssertSelectedHitObject(h =>
{
var romajiTags = h.RomajiTags;
Assert.AreEqual(1, romajiTags.Count);
Assert.AreEqual("kaze", romajiTags[0].Text);
});
}

[Test]
public void TestAutoGenerateRomajiTagsWithNonSupportedLyric()
{
PrepareHitObjects(() => new[]
{
new Lyric
{
Text = "風",
},
new Lyric
{
Text = string.Empty,
},
new Lyric
{
Text = string.Empty,
Language = new CultureInfo(17)
},
});

TriggerHandlerChangedWithException<GeneratorNotSupportedException>(c => c.AutoGenerate());
}

#endregion

[Test]
public void TestAdd()
{
Expand Down
Loading