summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-05-11 21:33:36 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-05-11 21:33:36 (GMT)
commitd2861533cc53fbcc217048bafebf34b1f70ba3aa (patch)
tree28c847a8093761fcaa0916be54445328d843096d /tests
parent6c9e1b5f7ee0915036d47b83f1e34b87b44b1723 (diff)
Updated the API for buffer caches.
Diffstat (limited to 'tests')
-rw-r--r--tests/glibext/buffercache.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/glibext/buffercache.py b/tests/glibext/buffercache.py
new file mode 100644
index 0000000..30488f7
--- /dev/null
+++ b/tests/glibext/buffercache.py
@@ -0,0 +1,49 @@
+
+from chrysacase import ChrysalideTestCase
+from gi.repository import GObject
+from pychrysalide.analysis.contents import MemoryContent
+from pychrysalide.glibext import BufferCache
+from pychrysalide.glibext import BufferLine
+from pychrysalide.glibext import LineGenerator
+
+
+class CommentBuilder(GObject.Object, LineGenerator):
+ def _count_lines(self):
+ return 1
+ def _get_flags(self, index, repeat):
+ return BufferLine.BufferLineFlags.NONE
+ def _print(self, line, index, repeat, content):
+ line.append_text(0, '# Comment', BufferLine.RenderingTagType.PRINTABLE)
+
+
+class TestBufferCache(ChrysalideTestCase):
+ """TestCase for glibext.BufferCache*"""
+
+ def testCacheConstructor(self):
+ """Build all possible kinds of buffer caches."""
+
+ cache = BufferCache()
+ self.assertIsNotNone(cache)
+ self.assertIsNone(cache.content)
+
+ cache = BufferCache(None)
+ self.assertIsNotNone(cache)
+ self.assertIsNone(cache.content)
+
+ cnt = MemoryContent(b'\x00' * 8)
+
+ cache = BufferCache(cnt)
+ self.assertIsNotNone(cache)
+ self.assertIsNotNone(cache.content)
+
+
+ def testCacheRendering(self):
+ """Check a buffer cache simple content."""
+
+ cache = BufferCache()
+
+ cache.append(CommentBuilder(), BufferLine.BufferLineFlags.NONE)
+
+ cache.append(CommentBuilder())
+
+ self.assertEqual(2, cache.lines_count)