test_lyric.py 773 Bytes
from etl_to_crawler.lyric import strip_timestamps

def test_strips_standard_timestamps():
    lrc = "[00:12.34]第一行歌词\n[01:23.45]第二行歌词"
    assert strip_timestamps(lrc) == "第一行歌词\n第二行歌词"

def test_strips_millisecond_timestamps():
    lrc = "[00:12.345]带三位毫秒"
    assert strip_timestamps(lrc) == "带三位毫秒"

def test_strips_meta_tags():
    lrc = "[ti:歌曲名]\n[ar:歌手]\n[00:01.00]歌词"
    result = strip_timestamps(lrc)
    assert "歌词" in result
    assert "[ti:" not in result

def test_empty_and_none():
    assert strip_timestamps(None) == ''
    assert strip_timestamps('') == ''

def test_plain_text_unchanged():
    assert strip_timestamps("没有时间戳的歌词") == "没有时间戳的歌词"