segment tests

This commit is contained in:
Will McGugan 2019-12-11 18:53:51 +00:00
parent 57afd9303f
commit ab0214ea53
2 changed files with 22 additions and 2 deletions

View file

@ -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