Skip to content

Commit

Permalink
Create the TestCaseTextIndexHelper.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Dec 6, 2023
1 parent e7a4b76 commit f023c3d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions LrcParser.Tests/Helper/TestCaseTextIndexHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.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("(?<index>[-0-9]+),(?<state>start|end)");
var result = regex.Match(str);
if (!result.Success)
throw new RegexMatchTimeoutException(nameof(str));

int index = result.GetGroupValue<int>("index");
var state = result.GetGroupValue<string>("state") == "start" ? IndexState.Start : IndexState.End;

return new TextIndex(index, state);
}
}

0 comments on commit f023c3d

Please sign in to comment.