From 639be9db198aed6860ded0ff86a707a5be776935 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 25 Jul 2024 21:30:49 +0800 Subject: [PATCH] Use the test case source instead of test cases because it's not a good way to combine lots of property into object inside the test case. --- .../Parser/Kar/Lines/KarLyricParserTest.cs | 124 +++++++++++--- .../Parser/Kar/Lines/KarRubyParserTest.cs | 152 ++++++++++++++---- .../Parser/Lrc/Lines/LrcLyricParserTest.cs | 124 +++++++++++--- 3 files changed, 326 insertions(+), 74 deletions(-) diff --git a/LrcParser.Tests/Parser/Kar/Lines/KarLyricParserTest.cs b/LrcParser.Tests/Parser/Kar/Lines/KarLyricParserTest.cs index 271d35b..393b065 100644 --- a/LrcParser.Tests/Parser/Kar/Lines/KarLyricParserTest.cs +++ b/LrcParser.Tests/Parser/Kar/Lines/KarLyricParserTest.cs @@ -1,6 +1,7 @@ // Copyright (c) karaoke.dev . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; using LrcParser.Parser.Kar.Lines; using LrcParser.Parser.Kar.Metadata; using LrcParser.Tests.Helper; @@ -22,38 +23,115 @@ public void TestCanDecode(string text, bool expected) Assert.That(actual, Is.EqualTo(expected)); } - [TestCase("[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", "帰り道は", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" })] - [TestCase("帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", "帰り道は", new[] { "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" })] - [TestCase("[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は", "帰り道は", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940" })] - [TestCase("帰り道は", "帰り道は", new string[] { })] - [TestCase("", "", new string[] { })] - [TestCase(null, "", new string[] { })] - public void TestDecode(string lyric, string text, string[] timeTags) + [TestCaseSource(nameof(testDecodeSource))] + public void TestDecode(string lyric, KarLyric expected) { - var expected = new KarLyric - { - Text = text, - TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), - }; var actual = Decode(lyric); Assert.That(actual, Is.EqualTo(expected)); } - [TestCase("帰り道は", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" }, "[00:17.97]帰[00:18.37]り[00:18.55]道[00:18.94]は[00:19.22]")] - [TestCase("帰り道は", new[] { "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" }, "帰[00:18.37]り[00:18.55]道[00:18.94]は[00:19.22]")] - [TestCase("帰り道は", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940" }, "[00:17.97]帰[00:18.37]り[00:18.55]道[00:18.94]は")] - [TestCase("帰り道は", new string[] { }, "帰り道は")] - [TestCase("", new string[] { }, "")] - public void TestEncode(string text, string[] timeTags, string expected) + private static IEnumerable testDecodeSource => new object[][] + { + [ + "[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", + new KarLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220"]), + }, + ], + [ + "帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", + new KarLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220"]), + }, + ], + [ + "[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は", + new KarLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940"]), + }, + ], + [ + "帰り道は", + new KarLyric + { + Text = "帰り道は", + TimeTags = [], + }, + ], + [ + "", + new KarLyric + { + Text = "", + TimeTags = [], + }, + ], + [ + null!, + new KarLyric + { + Text = "", + TimeTags = [], + }, + ], + }; + + [TestCaseSource(nameof(testEncodeSource))] + public void TestEncode(KarLyric lyric, string expected) { - var lyric = new KarLyric - { - Text = text, - TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), - }; var actual = Encode(lyric); Assert.That(actual, Is.EqualTo(expected)); } + + private static IEnumerable testEncodeSource => new object[][] + { + [ + new KarLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220"]), + }, + "[00:17.97]帰[00:18.37]り[00:18.55]道[00:18.94]は[00:19.22]", + ], + [ + new KarLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220"]), + }, + "帰[00:18.37]り[00:18.55]道[00:18.94]は[00:19.22]", + ], + [ + new KarLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940"]), + }, + "[00:17.97]帰[00:18.37]り[00:18.55]道[00:18.94]は", + ], + [ + new KarLyric + { + Text = "帰り道は", + TimeTags = [], + }, + "帰り道は", + ], + [ + new KarLyric + { + Text = "", + TimeTags = [], + }, + "", + ], + }; } diff --git a/LrcParser.Tests/Parser/Kar/Lines/KarRubyParserTest.cs b/LrcParser.Tests/Parser/Kar/Lines/KarRubyParserTest.cs index ef52f8c..ec9f5ab 100644 --- a/LrcParser.Tests/Parser/Kar/Lines/KarRubyParserTest.cs +++ b/LrcParser.Tests/Parser/Kar/Lines/KarRubyParserTest.cs @@ -1,6 +1,8 @@ // Copyright (c) karaoke.dev . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; +using System.Collections.Generic; using LrcParser.Parser.Kar.Lines; using LrcParser.Parser.Kar.Metadata; using LrcParser.Tests.Helper; @@ -22,43 +24,137 @@ public void TestCanDecode(string text, bool expected) Assert.That(actual, Is.EqualTo(expected)); } - [TestCase("@Ruby1=帰,かえ,[00:53:19],[01:24:77]", "帰", "かえ", new string[] { }, 53190, 84770)] - [TestCase("@Ruby1=帰,かえ,[01:24:77]", "帰", "かえ", new string[] { }, 84770, null)] - [TestCase("@Ruby1=帰,かえ,,[01:24:77]", "帰", "かえ", new string[] { }, null, 84770)] - [TestCase("@Ruby1=帰,かえ", "帰", "かえ", new string[] { }, null, null)] - [TestCase("@Ruby1=帰,か[00:00:50]え", "帰", "かえ", new[] { "[1,start]:500" }, null, null)] - public void TestDecode(string rubyTag, string parent, string ruby, string[] timeTags, int? startTime, int? endTime) + [TestCaseSource(nameof(testDecodeSource))] + public void TestDecode(string rubyTag, KarRuby expected) { - var expected = new KarRuby - { - Parent = parent, - Ruby = ruby, - TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), - StartTime = startTime, - EndTime = endTime, - }; var actual = Decode(rubyTag); Assert.That(actual, Is.EqualTo(expected)); } - [TestCase("帰", "かえ", new string[] { }, 53190, 84770, "@Ruby1=帰,かえ,[00:53.19],[01:24.77]")] - [TestCase("帰", "かえ", new string[] { }, 84770, null, "@Ruby1=帰,かえ,[01:24.77]")] - [TestCase("帰", "かえ", new string[] { }, null, 84770, "@Ruby1=帰,かえ,,[01:24.77]")] - [TestCase("帰", "かえ", new string[] { }, null, null, "@Ruby1=帰,かえ")] - [TestCase("帰", "かえ", new[] { "[1,start]:500" }, null, null, "@Ruby1=帰,か[00:00.50]え")] - public void TestEncode(string parent, string ruby, string[] timeTags, int? startTime, int? endTime, string expected) + private static IEnumerable testDecodeSource => new object[][] + { + [ + "@Ruby1=帰,かえ,[00:53:19],[01:24:77]", + new KarRuby + { + Parent = "帰", + Ruby = "かえ", + TimeTags = TestCaseTagHelper.ParseTimeTags(Array.Empty()), + StartTime = 53190, + EndTime = 84770, + }, + ], + [ + "@Ruby1=帰,かえ,[01:24:77]", + new KarRuby + { + Parent = "帰", + Ruby = "かえ", + TimeTags = TestCaseTagHelper.ParseTimeTags(Array.Empty()), + StartTime = 84770, + EndTime = null, + }, + ], + [ + "@Ruby1=帰,かえ,,[01:24:77]", + new KarRuby + { + Parent = "帰", + Ruby = "かえ", + TimeTags = TestCaseTagHelper.ParseTimeTags(Array.Empty()), + StartTime = null, + EndTime = 84770, + }, + ], + [ + "@Ruby1=帰,かえ", + new KarRuby + { + Parent = "帰", + Ruby = "かえ", + TimeTags = TestCaseTagHelper.ParseTimeTags(Array.Empty()), + StartTime = null, + EndTime = null, + }, + ], + [ + "@Ruby1=帰,か[00:00:50]え", + new KarRuby + { + Parent = "帰", + Ruby = "かえ", + TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { "[1,start]:500" }), + StartTime = null, + EndTime = null, + }, + ], + }; + + [TestCaseSource(nameof(testEncodeSources))] + public void TestEncode(KarRuby rubyTag, string expected) { - var rubyTag = new KarRuby - { - Parent = parent, - Ruby = ruby, - TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), - StartTime = startTime, - EndTime = endTime, - }; var actual = Encode(rubyTag); Assert.That(actual, Is.EqualTo(expected)); } + + private static IEnumerable testEncodeSources => new object[][] + { + [ + new KarRuby + { + Parent = "帰", + Ruby = "かえ", + TimeTags = [], + StartTime = 53190, + EndTime = 84770, + }, + "@Ruby1=帰,かえ,[00:53.19],[01:24.77]", + ], + [ + new KarRuby + { + Parent = "帰", + Ruby = "かえ", + TimeTags = [], + StartTime = 84770, + EndTime = null, + }, + "@Ruby1=帰,かえ,[01:24.77]", + ], + [ + new KarRuby + { + Parent = "帰", + Ruby = "かえ", + TimeTags = [], + StartTime = null, + EndTime = 84770, + }, + "@Ruby1=帰,かえ,,[01:24.77]", + ], + [ + new KarRuby + { + Parent = "帰", + Ruby = "かえ", + TimeTags = [], + StartTime = null, + EndTime = null, + }, + "@Ruby1=帰,かえ", + ], + [ + new KarRuby + { + Parent = "帰", + Ruby = "かえ", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[1,start]:500"]), + StartTime = null, + EndTime = null, + }, + "@Ruby1=帰,か[00:00.50]え", + ], + }; } diff --git a/LrcParser.Tests/Parser/Lrc/Lines/LrcLyricParserTest.cs b/LrcParser.Tests/Parser/Lrc/Lines/LrcLyricParserTest.cs index 30a364a..333bf3e 100644 --- a/LrcParser.Tests/Parser/Lrc/Lines/LrcLyricParserTest.cs +++ b/LrcParser.Tests/Parser/Lrc/Lines/LrcLyricParserTest.cs @@ -1,6 +1,7 @@ // Copyright (c) karaoke.dev . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; using LrcParser.Parser.Lrc.Lines; using LrcParser.Parser.Lrc.Metadata; using LrcParser.Tests.Helper; @@ -21,38 +22,115 @@ public void TestCanDecode(string text, bool expected) Assert.That(actual, Is.EqualTo(expected)); } - [TestCase("[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", "帰り道は", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" })] - [TestCase("帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", "帰り道は", new[] { "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" })] - [TestCase("[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は", "帰り道は", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940" })] - [TestCase("帰り道は", "帰り道は", new string[] { })] - [TestCase("", "", new string[] { })] - [TestCase(null, "", new string[] { })] - public void TestDecode(string lyric, string text, string[] timeTags) + [TestCaseSource(nameof(testDecodeSource))] + public void TestDecode(string lyric, LrcLyric expected) { - var expected = new LrcLyric - { - Text = text, - TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), - }; var actual = Decode(lyric); Assert.That(actual, Is.EqualTo(expected)); } - [TestCase("帰り道は", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" }, "[00:17.97]帰[00:18.37]り[00:18.55]道[00:18.94]は[00:19.22]")] - [TestCase("帰り道は", new[] { "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" }, "帰[00:18.37]り[00:18.55]道[00:18.94]は[00:19.22]")] - [TestCase("帰り道は", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940" }, "[00:17.97]帰[00:18.37]り[00:18.55]道[00:18.94]は")] - [TestCase("帰り道は", new string[] { }, "帰り道は")] - [TestCase("", new string[] { }, "")] - public void TestEncode(string text, string[] timeTags, string expected) + private static IEnumerable testDecodeSource => new object[][] + { + [ + "[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", + new LrcLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220"]), + }, + ], + [ + "帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", + new LrcLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220"]), + }, + ], + [ + "[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は", + new LrcLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940"]), + }, + ], + [ + "帰り道は", + new LrcLyric + { + Text = "帰り道は", + TimeTags = [], + }, + ], + [ + "", + new LrcLyric + { + Text = "", + TimeTags = [], + }, + ], + [ + null!, + new LrcLyric + { + Text = "", + TimeTags = [], + }, + ], + }; + + [TestCaseSource(nameof(testEncodeSource))] + public void TestEncode(LrcLyric lyric, string expected) { - var lyric = new LrcLyric - { - Text = text, - TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), - }; var actual = Encode(lyric); Assert.That(actual, Is.EqualTo(expected)); } + + private static IEnumerable testEncodeSource => new object[][] + { + [ + new LrcLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220"]), + }, + "[00:17.97]帰[00:18.37]り[00:18.55]道[00:18.94]は[00:19.22]", + ], + [ + new LrcLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220"]), + }, + "帰[00:18.37]り[00:18.55]道[00:18.94]は[00:19.22]", + ], + [ + new LrcLyric + { + Text = "帰り道は", + TimeTags = TestCaseTagHelper.ParseTimeTags(["[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940"]), + }, + "[00:17.97]帰[00:18.37]り[00:18.55]道[00:18.94]は", + ], + [ + new LrcLyric + { + Text = "帰り道は", + TimeTags = [], + }, + "帰り道は", + ], + [ + new LrcLyric + { + Text = "", + TimeTags = [], + }, + "", + ], + }; }