Skip to content

Commit

Permalink
test single cell widths
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Oct 22, 2024
1 parent be42f1b commit b93d3b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion rich/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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


Expand Down
23 changes: 22 additions & 1 deletion tests/test_cells.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import string

from rich import cells
from rich.cells import chop_cells
from rich.cells import _is_single_cell_widths, chop_cells


def test_cell_len_long_string():
Expand Down Expand Up @@ -59,3 +61,22 @@ def test_chop_cells_mixed_width():
"""Mixed single and double-width characters."""
text = "あ1り234が5と6う78"
assert chop_cells(text, 3) == ["あ1", "り2", "34", "が5", "と6", "う7", "8"]


def test_is_single_cell_widths() -> None:
# Check _is_single_cell_widths reports correctly
for character in string.printable:
if ord(character) >= 32:
assert _is_single_cell_widths(character)

BOX = "┌─┬┐│ ││├─┼┤│ ││├─┼┤├─┼┤│ ││└─┴┘"

for character in BOX:
print(repr(character))
assert _is_single_cell_widths(character)

for character in "💩":
assert not _is_single_cell_widths(character)

for character in "わさび":
assert not _is_single_cell_widths(character)
28 changes: 1 addition & 27 deletions tests/test_segment.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import string
from io import StringIO

import pytest

from rich.cells import cell_len
from rich.segment import (
ControlType,
Segment,
SegmentLines,
Segments,
_is_single_cell_widths,
)
from rich.segment import ControlType, Segment, SegmentLines, Segments
from rich.style import Style


Expand Down Expand Up @@ -385,22 +378,3 @@ def test_align_bottom():
[Segment(" ", Style())],
[Segment("X")],
]


def test_is_single_cell_widths() -> None:
# Check _is_single_cell_widths reports correctly
for character in string.printable:
if ord(character) >= 32:
assert _is_single_cell_widths(character)

BOX = "┌─┬┐│ ││├─┼┤│ ││├─┼┤├─┼┤│ ││└─┴┘"

for character in BOX:
print(repr(character))
assert _is_single_cell_widths(character)

for character in "💩":
assert not _is_single_cell_widths(character)

for character in "わさび":
assert not _is_single_cell_widths(character)

0 comments on commit b93d3b6

Please sign in to comment.