Skip to content

Commit b93d3b6

Browse files
committed
test single cell widths
1 parent be42f1b commit b93d3b6

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

rich/cells.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# Regex to match sequence of the most common character ranges
1010
_is_single_cell_widths = re.compile(
11-
"^[\u0020-\u007f\u00a0\u02ff\u0370-\u0482\u2500-\u25FF]*$"
11+
"^[\u0020-\u007e\u00a0\u02ff\u0370-\u0482\u2500-\u25FF]*$"
1212
).match
1313

1414

tests/test_cells.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import string
2+
13
from rich import cells
2-
from rich.cells import chop_cells
4+
from rich.cells import _is_single_cell_widths, chop_cells
35

46

57
def test_cell_len_long_string():
@@ -59,3 +61,22 @@ def test_chop_cells_mixed_width():
5961
"""Mixed single and double-width characters."""
6062
text = "あ1り234が5と6う78"
6163
assert chop_cells(text, 3) == ["あ1", "り2", "34", "が5", "と6", "う7", "8"]
64+
65+
66+
def test_is_single_cell_widths() -> None:
67+
# Check _is_single_cell_widths reports correctly
68+
for character in string.printable:
69+
if ord(character) >= 32:
70+
assert _is_single_cell_widths(character)
71+
72+
BOX = "┌─┬┐│ ││├─┼┤│ ││├─┼┤├─┼┤│ ││└─┴┘"
73+
74+
for character in BOX:
75+
print(repr(character))
76+
assert _is_single_cell_widths(character)
77+
78+
for character in "💩":
79+
assert not _is_single_cell_widths(character)
80+
81+
for character in "わさび":
82+
assert not _is_single_cell_widths(character)

tests/test_segment.py

+1-27
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import string
21
from io import StringIO
32

43
import pytest
54

65
from rich.cells import cell_len
7-
from rich.segment import (
8-
ControlType,
9-
Segment,
10-
SegmentLines,
11-
Segments,
12-
_is_single_cell_widths,
13-
)
6+
from rich.segment import ControlType, Segment, SegmentLines, Segments
147
from rich.style import Style
158

169

@@ -385,22 +378,3 @@ def test_align_bottom():
385378
[Segment(" ", Style())],
386379
[Segment("X")],
387380
]
388-
389-
390-
def test_is_single_cell_widths() -> None:
391-
# Check _is_single_cell_widths reports correctly
392-
for character in string.printable:
393-
if ord(character) >= 32:
394-
assert _is_single_cell_widths(character)
395-
396-
BOX = "┌─┬┐│ ││├─┼┤│ ││├─┼┤├─┼┤│ ││└─┴┘"
397-
398-
for character in BOX:
399-
print(repr(character))
400-
assert _is_single_cell_widths(character)
401-
402-
for character in "💩":
403-
assert not _is_single_cell_widths(character)
404-
405-
for character in "わさび":
406-
assert not _is_single_cell_widths(character)

0 commit comments

Comments
 (0)