Merge pull request #6160 from gvx/main

Fix str() + Content()
This commit is contained in:
Will McGugan
2025-10-11 10:52:43 +01:00
committed by GitHub
2 changed files with 11 additions and 3 deletions

View File

@@ -760,10 +760,10 @@ class Content(Visual):
return content
return NotImplemented
def __radd__(self, other: Content | str) -> Content:
if not isinstance(other, (Content, str)):
def __radd__(self, other: str) -> Content:
if not isinstance(other, str):
return NotImplemented
return self + other
return Content(other) + self
@classmethod
def _trim_spans(cls, text: str, spans: list[Span]) -> list[Span]:

View File

@@ -136,6 +136,14 @@ def test_add() -> None:
assert content.spans == [Span(0, 3, "red"), Span(4, 7, "blue")]
assert content.cell_length == 7
def test_radd() -> None:
"""Test reverse addition."""
assert "foo" + Content("bar") == Content("foobar")
# Test spans after addition
content = "foo " + Content.styled("bar", "blue")
assert str(content) == "foo bar"
assert content.spans == [Span(4, 7, "blue")]
def test_from_markup():
"""Test simple parsing of content markup."""