rich/tests/test_control.py

33 lines
932 B
Python
Raw Normal View History

2020-05-14 19:15:31 +00:00
from rich.control import Control, strip_control_codes
2021-03-22 20:26:01 +00:00
from rich.segment import Segment, ControlType
2020-05-14 19:15:31 +00:00
def test_control():
control = Control(ControlType.BELL)
assert str(control) == "\x07"
2020-05-12 10:15:59 +00:00
def test_strip_control_codes():
assert strip_control_codes("") == ""
assert strip_control_codes("foo\rbar") == "foobar"
assert strip_control_codes("Fear is the mind killer") == "Fear is the mind killer"
2021-03-22 20:26:01 +00:00
def test_control_move_to():
control = Control.move_to(5, 10)
print(control.segment)
assert control.segment == Segment(
"\x1b[11;6H", None, [(ControlType.CURSOR_MOVE_TO, 6, 11)]
)
def test_control_move():
assert Control.move(0, 0).segment == Segment("", None, [])
control = Control.move(3, 4)
print(repr(control.segment))
assert control.segment == Segment(
"\x1b[3C\x1b[4B",
None,
[(ControlType.CURSOR_FORWARD, 3), (ControlType.CURSOR_DOWN, 4)],
)