beets/test/util/test_layout.py
2026-03-14 12:02:30 +00:00

30 lines
1.2 KiB
Python

from unittest import TestCase
from beets.util.layout import split_into_lines
class LayoutTestCase(TestCase):
def test_split_into_lines(self):
# Test uncolored text
txt = split_into_lines("test test test", [5, 5, 5])
assert txt == ["test", "test", "test"]
# Test multiple colored texts
colored_text = "\x1b[31mtest \x1b[39;49;00m" * 3
split_txt = [
"\x1b[31mtest\x1b[39;49;00m",
"\x1b[31mtest\x1b[39;49;00m",
"\x1b[31mtest\x1b[39;49;00m",
]
txt = split_into_lines(colored_text, [5, 5, 5])
assert txt == split_txt
# Test single color, multi space text
colored_text = "\x1b[31m test test test \x1b[39;49;00m"
txt = split_into_lines(colored_text, [5, 5, 5])
assert txt == split_txt
# Test single color, different spacing
colored_text = "\x1b[31mtest\x1b[39;49;00mtest test test"
# ToDo: fix color_len to handle mid-text color escapes, and thus
# split colored texts over newlines (potentially with dashes?)
split_txt = ["\x1b[31mtest\x1b[39;49;00mt", "est", "test", "test"]
txt = split_into_lines(colored_text, [5, 5, 5])
assert txt == split_txt