diff --git a/LrcParser.Tests/Helper/TestCaseTextIndexHelper.cs b/LrcParser.Tests/Helper/TestCaseTextIndexHelper.cs new file mode 100644 index 0000000..768b0ca --- /dev/null +++ b/LrcParser.Tests/Helper/TestCaseTextIndexHelper.cs @@ -0,0 +1,24 @@ +// Copyright (c) karaoke.dev . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Text.RegularExpressions; +using LrcParser.Extension; +using LrcParser.Model; + +namespace LrcParser.Tests.Helper; + +public static class TestCaseTextIndexHelper +{ + public static TextIndex ParseTextIndex(string str) + { + var regex = new Regex("(?[-0-9]+),(?start|end)"); + var result = regex.Match(str); + if (!result.Success) + throw new RegexMatchTimeoutException(nameof(str)); + + int index = result.GetGroupValue("index"); + var state = result.GetGroupValue("state") == "start" ? IndexState.Start : IndexState.End; + + return new TextIndex(index, state); + } +}