Skip to content

Commit

Permalink
test(lyrics): add test for parseLrc util
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Jan 8, 2023
1 parent d25e2db commit 0714888
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/components/lyrics.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, test } from "vitest";
import { parseLrc } from "./lyrics";

describe("parseLrc", () => {
const lrc = `
[00:00.000] 作词 : James Alyn Wee/Kasidej Hongladaromp
[00:01.000] 作曲 : James Alyn Wee/Kasidej Hongladaromp
[00:28.836] I'm just laying on the floor again`;

test("Parse raw lrc to [[time, text]] format", () => {
expect(parseLrc(lrc)).toEqual([
[0, "作词 : James Alyn Wee/Kasidej Hongladaromp"],
[1, "作曲 : James Alyn Wee/Kasidej Hongladaromp"],
[28.836, "I'm just laying on the floor again"],
]);
});
});
2 changes: 1 addition & 1 deletion src/components/lyrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function Lyrics({ lrcText, currentTime }: LyricsProps) {
*
* @return {String} [[time, text], [time, text], [time, text], ...]
*/
function parseLrc(lrc_s?: string): [time: number, text: string][] {
export function parseLrc(lrc_s?: string): [time: number, text: string][] {
if (lrc_s) {
lrc_s = lrc_s.replace(/([^\]^\n])\[/g, (match, p1) => p1 + "\n[");
const lyric = lrc_s.split("\n");
Expand Down

0 comments on commit 0714888

Please sign in to comment.