[meld] test: Add coverage for new Bufferlines caching behaviour
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] test: Add coverage for new Bufferlines caching behaviour
- Date: Sat, 7 Aug 2021 23:17:16 +0000 (UTC)
commit e2377909d8f42c1af54c67c0533136997a47834e
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Aug 8 08:28:37 2021 +1000
test: Add coverage for new Bufferlines caching behaviour
test/test_buffer_lines.py | 70 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 68 insertions(+), 2 deletions(-)
---
diff --git a/test/test_buffer_lines.py b/test/test_buffer_lines.py
index f8b1acd8..f5e9b032 100644
--- a/test/test_buffer_lines.py
+++ b/test/test_buffer_lines.py
@@ -15,8 +15,7 @@ text = ("""0
7
8
9
-10
-""")
+10""")
@pytest.fixture(scope='module', autouse=True)
@@ -53,3 +52,70 @@ def test_meld_buffer_slicing(
buffer, buffer_lines = buffer_setup
assert buffer_lines[line_start:line_end] == expected_text
+
+
+def test_meld_buffer_index_out_of_range(buffer_setup):
+
+ buffer, buffer_lines = buffer_setup
+ with pytest.raises(IndexError):
+ buffer_lines[11]
+
+
+def test_meld_buffer_cached_contents(buffer_setup):
+
+ buffer, buffer_lines = buffer_setup
+ text_lines = text.splitlines()
+ assert len(buffer_lines.lines) == len(buffer_lines) == len(text_lines)
+
+ # Check that without access, we have no cached contents
+ assert buffer_lines.lines == [None] * len(text_lines)
+
+ # Access the lines so that they're cached
+ buffer_lines[:]
+
+ # Note that this only happens to be true for our simple text; if
+ # it were true in general, we wouldn't need the complexities of the
+ # BufferLines class.
+ assert buffer_lines.lines == text_lines
+
+
+def test_meld_buffer_insert_text(buffer_setup):
+
+ buffer, buffer_lines = buffer_setup
+
+ # Access the lines so that they're cached
+ buffer_lines[:]
+
+ assert buffer_lines.lines[4:8] == ["4", "5", "6", "7"]
+
+ # Delete from the start of line 5 to the start of line 7,
+ # invalidating line 7 but leaving its contents intact.
+ buffer.insert(
+ buffer.get_iter_at_line(5),
+ "hey\nthings",
+ )
+ assert buffer_lines.lines[4:8] == ["4", None, None, "6"]
+
+ assert buffer_lines[5:7] == ["hey", "things5"]
+ assert buffer_lines.lines[4:8] == ["4", "hey", "things5", "6"]
+
+
+def test_meld_buffer_delete_range(buffer_setup):
+
+ buffer, buffer_lines = buffer_setup
+
+ # Access the lines so that they're cached
+ buffer_lines[:]
+
+ assert buffer_lines.lines[4:8] == ["4", "5", "6", "7"]
+
+ # Delete from the start of line 5 to the start of line 7,
+ # invalidating line 7 but leaving its contents intact.
+ buffer.delete(
+ buffer.get_iter_at_line(5),
+ buffer.get_iter_at_line(7),
+ )
+ assert buffer_lines.lines[4:7] == ["4", None, "8"]
+
+ assert buffer_lines[5] == "7"
+ assert buffer_lines.lines[4:7] == ["4", "7", "8"]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]