MCPcopy
hub / github.com/Textualize/rich / test_slice

Function test_slice

tests/test_text.py:992–1003  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

990
991
992def test_slice():
993 text = Text.from_markup("[red]foo [bold]bar[/red] baz[/bold]")
994 assert text[0] == Text("f", spans=[Span(0, 1, "red")])
995 assert text[4] == Text("b", spans=[Span(0, 1, "red"), Span(0, 1, "bold")])
996
997 assert text[:3] == Text("foo", spans=[Span(0, 3, "red")])
998 assert text[:4] == Text("foo ", spans=[Span(0, 4, "red")])
999 assert text[:5] == Text("foo b", spans=[Span(0, 5, "red"), Span(4, 5, "bold")])
1000 assert text[4:] == Text("bar baz", spans=[Span(0, 3, "red"), Span(0, 7, "bold")])
1001
1002 with pytest.raises(TypeError):
1003 text[::-1]
1004
1005
1006def test_wrap_invalid_style():

Callers

nothing calls this directly

Calls 3

TextClass · 0.90
SpanClass · 0.90
from_markupMethod · 0.80

Tested by

no test coverage detected