Repository: Textualize/rich
File: tests/test_cells.py (Python)

Code before:
        ("⬇", [(0, 1, 1)], 1),
        ("⬇️", [(0, 2, 2)], 2),  # Variation selector, makes it double width
        ("♻", [(0, 1, 1)], 1),
        ("♻️", [(0, 2, 2)], 2),
        ("♻♻️", [(0, 1, 1), (1, 3, 2)], 3),
        ("\x1b", [(0, 1, 0)], 0),  # One escape sahould have zero width
        ("\x1b\x1b", [(0, 2, 0)], 0),  # Two escapes should have zero width
        (
            "\ufe0f",
            [(0, 1, 0)],
            0,
        ),  # Variation selector 16, without anything to change should have zero width
        (
            "\ufe0f\ufe0f",
            [(0, 2, 0)],
            0,
        ),  # 2 X variation selector 16, without anything to change should have zero width
        (
            "\u200d",
            [(0, 1, 0)],
            0,
        ),  # A zero width joiner within noting prior should have zero width
        (
            "\u200d\u200d",
            [(0, 2, 0)],
            0,
        ),  # Two ZWJs should have zero width
    ],
)
def test_split_graphemes(
    text: str, expected_spans: list[CellSpan], expected_cell_length: int
):
    spans, cell_length = split_graphemes(text)
    print(spans)
    assert cell_len(text) == expected_cell_length
    assert spans == expected_spans
    assert cell_length == expected_cell_length


def test_nerd_font():
    """Regression test for https://github.com/Textualize/rich/issues/3943"""
    # Not allocated by unicode, but used by nerd fonts
    assert cell_len("\U000f024d") == 1


def test_zwj():
    """Test special case of zero width joiners"""
    assert cell_len("") == 0
    assert cell_len("\u200d") == 0
    assert cell_len("1\u200d") == 1
    # This sequence should really produce 2, but it aligns with with wcwidth

Review comment (bug):
Remove the `print(spans)` debug output from this test; it will add noise to test runs/CI output and isn't needed for assertions.

Code after:
        ("⬇", [(0, 1, 1)], 1),
        ("⬇️", [(0, 2, 2)], 2),  # Variation selector, makes it double width
        ("♻", [(0, 1, 1)], 1),
        ("♻️", [(0, 2, 2)], 2),
        ("♻♻️", [(0, 1, 1), (1, 3, 2)], 3),
        ("\x1b", [(0, 1, 0)], 0),  # One escape should have zero width
        ("\x1b\x1b", [(0, 2, 0)], 0),  # Two escapes should have zero width
        (
            "\ufe0f",
            [(0, 1, 0)],
            0,
        ),  # Variation selector 16, without anything to change should have zero width
        (
            "\ufe0f\ufe0f",
            [(0, 2, 0)],
            0,
        ),  # 2 X variation selector 16, without anything to change should have zero width
        (
            "\u200d",
            [(0, 1, 0)],
            0,
        ),  # A zero width joiner within noting prior should have zero width
        (
            "\u200d\u200d",
            [(0, 2, 0)],
            0,
        ),  # Two ZWJs should have zero width
    ],
)
def test_split_graphemes(
    text: str, expected_spans: list[CellSpan], expected_cell_length: int
):
    spans, cell_length = split_graphemes(text)
    print(spans)
    assert cell_len(text) == expected_cell_length
    assert spans == expected_spans
    assert cell_length == expected_cell_length


def test_nerd_font():
    """Regression test for https://github.com/Textualize/rich/issues/3943"""
    # Not allocated by unicode, but used by nerd fonts
    assert cell_len("\U000f024d") == 1


def test_zwj():
    """Test special case of zero width joiners"""
    assert cell_len("") == 0
    assert cell_len("\u200d") == 0
    assert cell_len("1\u200d") == 1
    # This sequence should really produce 2, but it aligns with with wcwidth