mirror of
https://github.com/Textualize/rich.git
synced 2025-08-03 01:32:26 +00:00
segment tests
This commit is contained in:
parent
57afd9303f
commit
ab0214ea53
2 changed files with 22 additions and 2 deletions
|
@ -43,7 +43,7 @@ class Segment(NamedTuple):
|
|||
|
||||
@classmethod
|
||||
def split_and_crop_lines(
|
||||
cls, segments: Iterable[Segment], length: int, wrap=False
|
||||
cls, segments: Iterable[Segment], length: int
|
||||
) -> Iterable[List[Segment]]:
|
||||
"""Split segments in to lines, and crop lines greater than a given length.
|
||||
|
||||
|
@ -193,7 +193,7 @@ class Segment(NamedTuple):
|
|||
yield last_segment
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
lines = [[Segment("Hello")]]
|
||||
lines = Segment.set_shape(lines, 50, 4, style=Style.parse("on blue"))
|
||||
for line in lines:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from rich.segment import Segment
|
||||
from rich.style import Style
|
||||
|
||||
|
||||
def test_repr():
|
||||
|
@ -7,3 +8,22 @@ def test_repr():
|
|||
|
||||
def test_line():
|
||||
assert Segment.line() == Segment("\n")
|
||||
|
||||
|
||||
def test_apply_style():
|
||||
segments = [Segment("foo"), Segment("bar", Style(bold=True))]
|
||||
assert Segment.apply_style(segments, None) is segments
|
||||
assert list(Segment.apply_style(segments, Style(italic=True))) == [
|
||||
Segment("foo", Style(italic=True)),
|
||||
Segment("bar", Style(italic=True, bold=True)),
|
||||
]
|
||||
|
||||
|
||||
def test_split_and_crop_lines():
|
||||
assert list(
|
||||
Segment.split_and_crop_lines([Segment("Hello\nWorld!\n"), Segment("foo")], 4)
|
||||
) == [[Segment("Hell")], [Segment("Worl")], [Segment("foo")]]
|
||||
|
||||
|
||||
def test_get_line_length():
|
||||
assert Segment.get_line_length([Segment("foo"), Segment("bar")]) == 6
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue