replace is_control with list of control codes

This commit is contained in:
Will McGugan 2021-03-14 11:47:03 +00:00
parent 6f972a059a
commit a998f23084
14 changed files with 188 additions and 156 deletions

View file

@ -1,10 +1,15 @@
from rich.segment import ControlCode, ControlType
from rich.segment import Segment
from rich.style import Style
def test_repr():
assert repr(Segment("foo")) == "Segment('foo', None)"
assert repr(Segment.control("foo")) == "Segment.control('foo', None)"
home = (ControlType.HOME, 0)
assert (
repr(Segment("foo", None, [home]))
== "Segment('foo', None, [(<ControlType.HOME: 3>, 0)])"
)
def test_line():
@ -81,10 +86,11 @@ def test_simplify():
def test_filter_control():
segments = [Segment("foo"), Segment("bar", is_control=True)]
control_code = (ControlType.HOME, 0)
segments = [Segment("foo"), Segment("bar", None, (control_code,))]
assert list(Segment.filter_control(segments)) == [Segment("foo")]
assert list(Segment.filter_control(segments, is_control=True)) == [
Segment("bar", is_control=True)
Segment("bar", None, (control_code,))
]
@ -107,11 +113,3 @@ def test_remove_color():
Segment("foo", Style(bold=True)),
Segment("bar", None),
]
def test_make_control():
segments = [Segment("foo"), Segment("bar")]
assert Segment.make_control(segments) == [
Segment.control("foo"),
Segment.control("bar"),
]