forked from karaoke-dev/LrcParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy the kar file format from the lrc folder.
Because we need to adjust the lrc file format see: karaoke-dev#40
- Loading branch information
1 parent
af39096
commit 2d2e1ea
Showing
12 changed files
with
1,451 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,60 @@ | ||
// Copyright (c) karaoke.dev <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using LrcParser.Parser.Kar.Lines; | ||
using LrcParser.Parser.Kar.Metadata; | ||
using LrcParser.Tests.Helper; | ||
using LrcParser.Tests.Parser.Lines; | ||
using NUnit.Framework; | ||
|
||
namespace LrcParser.Tests.Parser.Kar.Lines; | ||
|
||
public class KarLyricParserTest : BaseSingleLineParserTest<KarLyricParser, KarLyric> | ||
{ | ||
[TestCase("[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", true)] | ||
[TestCase("karaoke", true)] | ||
[TestCase("", false)] | ||
[TestCase(null, false)] | ||
[TestCase("@Ruby1=帰,かえ", true)] // will take off this if no other parser to process this line. | ||
public void TestCanDecode(string text, bool expected) | ||
{ | ||
var actual = CanDecode(text); | ||
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) | ||
{ | ||
var expected = new KarLyric | ||
{ | ||
Text = text, | ||
TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), | ||
}; | ||
var actual = Decode(lyric); | ||
|
||
Assert.That(actual.Text, Is.EqualTo(expected.Text)); | ||
Assert.That(actual.TimeTags, Is.EqualTo(expected.TimeTags)); | ||
} | ||
|
||
[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) | ||
{ | ||
var lyric = new KarLyric | ||
{ | ||
Text = text, | ||
TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), | ||
}; | ||
var actual = Encode(lyric); | ||
|
||
Assert.That(actual, Is.EqualTo(expected)); | ||
} | ||
} |
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,68 @@ | ||
// Copyright (c) karaoke.dev <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using LrcParser.Parser.Kar.Lines; | ||
using LrcParser.Parser.Kar.Metadata; | ||
using LrcParser.Tests.Helper; | ||
using LrcParser.Tests.Parser.Lines; | ||
using NUnit.Framework; | ||
|
||
namespace LrcParser.Tests.Parser.Kar.Lines; | ||
|
||
public class KarRubyParserTest : BaseSingleLineParserTest<KarRubyParser, KarRuby> | ||
{ | ||
[TestCase("@Ruby1=帰,かえ", true)] | ||
[TestCase("", false)] | ||
[TestCase(null, false)] | ||
[TestCase("[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", false)] | ||
[TestCase("karaoke", false)] | ||
public void TestCanDecode(string text, bool expected) | ||
{ | ||
var actual = CanDecode(text); | ||
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) | ||
{ | ||
var expected = new KarRuby | ||
{ | ||
Parent = parent, | ||
Ruby = ruby, | ||
TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), | ||
StartTime = startTime, | ||
EndTime = endTime, | ||
}; | ||
var actual = Decode(rubyTag); | ||
|
||
Assert.That(actual.Ruby, Is.EqualTo(expected.Ruby)); | ||
Assert.That(actual.Parent, Is.EqualTo(expected.Parent)); | ||
Assert.That(actual.TimeTags, Is.EqualTo(expected.TimeTags)); | ||
Assert.That(actual.StartTime, Is.EqualTo(expected.StartTime)); | ||
Assert.That(actual.EndTime, Is.EqualTo(expected.EndTime)); | ||
} | ||
|
||
[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) | ||
{ | ||
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)); | ||
} | ||
} |
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,43 @@ | ||
// Copyright (c) karaoke.dev <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using LrcParser.Parser.Kar.Utils; | ||
using LrcParser.Tests.Helper; | ||
using NUnit.Framework; | ||
|
||
namespace LrcParser.Tests.Parser.Kar.Utils; | ||
|
||
public class KarTimedTextUtilsTest | ||
{ | ||
[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:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", " 帰り道は", new[] { "[1,start]:17970", "[2,start]:18370", "[3,start]:18550", "[4,start]:18940", "[4,end]:19220" })] | ||
[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("[00:51.00][01:29.99][01:48.29][02:31.00][02:41.99]You gotta fight !", "You gotta fight !", new[] { "[0,start]:51000" })] // decode with invalid format. | ||
[TestCase("帰り道は", "帰り道は", new string[] { })] | ||
[TestCase("", "", new string[] { })] | ||
[TestCase(null, "", new string[] { })] | ||
public void TestDecode(string text, string expectedText, string[] expectedTimeTags) | ||
{ | ||
var (actualText, actualTimeTags) = KarTimedTextUtils.TimedTextToObject(text); | ||
|
||
Assert.That(actualText, Is.EqualTo(expectedText)); | ||
Assert.That(actualTimeTags, Is.EqualTo(TestCaseTagHelper.ParseTimeTags(expectedTimeTags))); | ||
} | ||
|
||
[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]:17970", "[2,start]:18370", "[3,start]:18550", "[4,start]:18940", "[4,end]:19220" }, " [00:17.97]帰[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", "[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) | ||
{ | ||
var actual = KarTimedTextUtils.ToTimedText(text, TestCaseTagHelper.ParseTimeTags(timeTags)); | ||
|
||
Assert.That(actual, Is.EqualTo(expected)); | ||
} | ||
} |
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,26 @@ | ||
// Copyright (c) karaoke.dev <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using LrcParser.Parser.Kar.Utils; | ||
using NUnit.Framework; | ||
|
||
namespace LrcParser.Tests.Parser.Kar.Utils; | ||
|
||
public class TimeTagUtilsTest | ||
{ | ||
[TestCase("[00:01:00]", 1000)] | ||
public void TestTimeTagToMillionSecond(string timeTag, int millionSecond) | ||
{ | ||
var actual = TimeTagUtils.TimeTagToMillionSecond(timeTag); | ||
|
||
Assert.That(actual, Is.EqualTo(millionSecond)); | ||
} | ||
|
||
[TestCase(1000, "[00:01.00]")] | ||
public void TestTimeTagToMillionSecond(int millionSecond, string timeTag) | ||
{ | ||
var actual = TimeTagUtils.MillionSecondToTimeTag(millionSecond); | ||
|
||
Assert.That(actual, Is.EqualTo(timeTag)); | ||
} | ||
} |
Oops, something went wrong.