summaryrefslogtreecommitdiffstats
path: root/tests/test_document.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:35:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:35:31 +0000
commit4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1 (patch)
treee5dee7be2f0d963da4faad6517278d03783e3adc /tests/test_document.py
parentInitial commit. (diff)
downloadprompt-toolkit-4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1.tar.xz
prompt-toolkit-4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1.zip
Adding upstream version 3.0.43.upstream/3.0.43
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_document.py')
-rw-r--r--tests/test_document.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/test_document.py b/tests/test_document.py
new file mode 100644
index 0000000..d052d53
--- /dev/null
+++ b/tests/test_document.py
@@ -0,0 +1,69 @@
+from __future__ import annotations
+
+import pytest
+
+from prompt_toolkit.document import Document
+
+
+@pytest.fixture
+def document():
+ return Document(
+ "line 1\n" + "line 2\n" + "line 3\n" + "line 4\n", len("line 1\n" + "lin")
+ )
+
+
+def test_current_char(document):
+ assert document.current_char == "e"
+ assert document.char_before_cursor == "n"
+
+
+def test_text_before_cursor(document):
+ assert document.text_before_cursor == "line 1\nlin"
+
+
+def test_text_after_cursor(document):
+ assert document.text_after_cursor == "e 2\n" + "line 3\n" + "line 4\n"
+
+
+def test_lines(document):
+ assert document.lines == ["line 1", "line 2", "line 3", "line 4", ""]
+
+
+def test_line_count(document):
+ assert document.line_count == 5
+
+
+def test_current_line_before_cursor(document):
+ assert document.current_line_before_cursor == "lin"
+
+
+def test_current_line_after_cursor(document):
+ assert document.current_line_after_cursor == "e 2"
+
+
+def test_current_line(document):
+ assert document.current_line == "line 2"
+
+
+def test_cursor_position(document):
+ assert document.cursor_position_row == 1
+ assert document.cursor_position_col == 3
+
+ d = Document("", 0)
+ assert d.cursor_position_row == 0
+ assert d.cursor_position_col == 0
+
+
+def test_translate_index_to_position(document):
+ pos = document.translate_index_to_position(len("line 1\nline 2\nlin"))
+
+ assert pos[0] == 2
+ assert pos[1] == 3
+
+ pos = document.translate_index_to_position(0)
+ assert pos == (0, 0)
+
+
+def test_is_cursor_at_the_end(document):
+ assert Document("hello", 5).is_cursor_at_the_end
+ assert not Document("hello", 4).is_cursor_at_the_end