mirror of https://github.com/Textualize/rich.git
test single cell widths
This commit is contained in:
parent
be42f1b082
commit
b93d3b6d98
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue