def test_kak_state(): kcr = FakeKcr( get_dict={"buffile": "/home/kakuser/abc.txt", "selection_desc": "101.1,377.9"} ) state = kak.get_state(kcr) assert state.buffer_path == "/home/kakuser/abc.txt" assert state.selection.range == line_range.LineRange(101, 377)
def __init__(self, selection_desc: str) -> None: """Parse a selction description from kakoune""" anchor_pos, cursor_pos = selection_desc.split(",") anchor_line = int(anchor_pos.split(".")[0]) cursor_line = int(cursor_pos.split(".")[0]) logging.debug(f"anchor at {anchor_line}; cursor at {cursor_line}") self._line_range = line_range.LineRange(min(anchor_line, cursor_line), max(anchor_line, cursor_line))
def test_parse_backwards_selection(): input_str = "50.20,29.99" selection = kak.SelectionDescription(input_str) assert selection.range == line_range.LineRange(29, 50)
def test_parse_multiline_selection(): input_str = "1.1,99.100" selection = kak.SelectionDescription(input_str) assert selection.range == line_range.LineRange(1, 99)
def test_parse_single_width(): input_str = "42.18,42.18" selection = kak.SelectionDescription(input_str) assert selection.range == line_range.LineRange(42, 42)
def test_single_line_range(): lr = line_range.LineRange(10, 10) assert str(lr) == "L10"
def test_line_range_not_equal_other_objects(): assert line_range.LineRange(1, 2) != "abc"
def test_line_range_inequality(): assert line_range.LineRange(1001, 7000) != line_range.LineRange(1, 2)
def test_line_range_equality(): assert line_range.LineRange(2, 8) == line_range.LineRange(2, 8)
def test_line_range_start_less_than_one(): with pytest.raises(ValueError): line_range.LineRange(0, 7)
def test_line_range_start_greater_than_stop(): with pytest.raises(ValueError): line_range.LineRange(8, 7)
def test_multiple_line_range(): lr = line_range.LineRange(7, 99) assert str(lr) == "L7-L99"