rich/tests/test_control.py

48 lines
1.4 KiB
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(
2021-03-25 21:08:36 +00:00
"\x1b[11;6H", None, [(ControlType.CURSOR_MOVE_TO, 5, 10)]
2021-03-22 20:26:01 +00:00
)
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)],
)
2021-03-25 21:08:36 +00:00
2021-06-17 21:31:08 +00:00
def test_move_to_column():
print(repr(Control.move_to_column(10, 20).segment))
assert Control.move_to_column(10, 20).segment == Segment(
"\x1b[11G\x1b[20B",
2021-03-25 21:08:36 +00:00
None,
2021-06-17 21:31:08 +00:00
[(ControlType.CURSOR_MOVE_TO_COLUMN, 10), (ControlType.CURSOR_DOWN, 20)],
2021-03-25 21:08:36 +00:00
)
2021-06-17 21:31:08 +00:00
assert Control.move_to_column(10, -20).segment == Segment(
"\x1b[11G\x1b[20A",
None,
[(ControlType.CURSOR_MOVE_TO_COLUMN, 10), (ControlType.CURSOR_UP, 20)],
2021-06-18 19:24:05 +00:00
)