Skip to content

Commit babf74a

Browse files
committed
more tests
1 parent 4f40703 commit babf74a

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

rich/segment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ def _split_cells(cls, segment: "Segment", cut: int) -> Tuple["Segment", "Segment
142142
)
143143
if out_by == -1 and cell_size(text[pos]) == 2:
144144
return (
145-
_Segment(before[:pos] + " ", style, control),
145+
_Segment(text[:pos] + " ", style, control),
146146
_Segment(" " + text[pos + 1 :], style, control),
147147
)
148-
if out_by == +1 and cell_size(text[pos]) == 2:
148+
if out_by == +1 and cell_size(text[pos - 1]) == 2:
149149
return (
150-
_Segment(before[: pos - 1] + " ", style, control),
150+
_Segment(text[: pos - 1] + " ", style, control),
151151
_Segment(" " + text[pos:], style, control),
152152
)
153153
if cell_pos < cut:

tests/test_segment.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,27 @@ def test_split_cells_emoji(text, split, result):
285285
assert Segment(text).split_cells(split) == result
286286

287287

288-
def test_split_cells_mixed() -> None:
289-
"""Check that split cells splits on cell positions."""
290-
# Caused https://github.com/Textualize/textual/issues/4996 in Textual
291-
tests = [
288+
@pytest.mark.parametrize(
289+
"segment",
290+
[
292291
Segment("早乙女リリエル (CV: 徳井青)"),
293-
Segment("メイド・イン・きゅんクチュアリ☆"),
292+
Segment("メイド・イン・きゅんクチュアリ☆ "),
294293
Segment("TVアニメ「メルクストーリア -無気力少年と瓶の中の少女-」 主題歌CD"),
295-
]
296-
for test in tests:
297-
for position in range(1, test.cell_length):
298-
left, right = Segment.split_cells(test, position)
299-
assert cell_len(left.text) == position
300-
assert cell_len(right.text) == test.cell_length - position
294+
Segment("南無阿弥JKうらめしや?! "),
295+
Segment("メルク (CV: 水瀬いのり) "),
296+
],
297+
)
298+
def test_split_cells_mixed(segment: Segment) -> None:
299+
"""Check that split cells splits on cell positions."""
300+
# Caused https://github.com/Textualize/textual/issues/4996 in Textual
301+
302+
for position in range(0, segment.cell_length + 1):
303+
left, right = Segment.split_cells(segment, position)
304+
assert all(
305+
cell_len(c) > 0 for c in segment.text
306+
) # Sanity check there aren't any sneaky control codes
307+
assert cell_len(left.text) == position
308+
assert cell_len(right.text) == segment.cell_length - position
301309

302310

303311
def test_split_cells_doubles() -> None:

0 commit comments

Comments
 (0)