From b93d3b6d98547b88320a5c82c362d5825bcdca4b Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 22 Oct 2024 16:13:14 +0100 Subject: [PATCH] test single cell widths --- rich/cells.py | 2 +- tests/test_cells.py | 23 ++++++++++++++++++++++- tests/test_segment.py | 28 +--------------------------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/rich/cells.py b/rich/cells.py index af8e81c7..4debea0c 100644 --- a/rich/cells.py +++ b/rich/cells.py @@ -8,7 +8,7 @@ from ._cell_widths import CELL_WIDTHS # 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 diff --git a/tests/test_cells.py b/tests/test_cells.py index fe451fa5..d694fb37 100644 --- a/tests/test_cells.py +++ b/tests/test_cells.py @@ -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(): @@ -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) diff --git a/tests/test_segment.py b/tests/test_segment.py index a9e64941..2264dbe5 100644 --- a/tests/test_segment.py +++ b/tests/test_segment.py @@ -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 @@ -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)