1. Ronny Pfannschmidt
  2. vimish

Commits

Ronny Pfannschmidt  committed 76803fd

refactor buffer tests, add buffer numbers

  • Participants
  • Parent commits 7d1ce3a
  • Branches default

Comments (0)

Files changed (3)

File tests/conftest.py

View file
 
-from vimish.engine import Engine
+from vimish.engine import Engine, Buffer
 
 
 class ConftestPlugin:
     def pytest_funcarg__engine(self, request):
         return Engine()
+
+    def pytest_funcarg__buffer(self, request):
+        return Buffer(Engine())

File tests/test_engine.py

View file
+from vimish.engine import Buffer
 
+def test_engine_buffer_id(engine):
 
-def test_buffer_line_count(engine):
-    buffer = engine.create_buffer()
+    buffer = Buffer(engine)
+    buffer2 = Buffer(engine)
+
+    assert buffer.bufnr == 1
+    assert buffer2.bufnr == 2
+
+def test_buffer_line_count(buffer):
 
     buffer.text = "Test\ntest2"
     assert len(buffer) == 2
     assert len(buffer) == 1
 
 
-def test_buffer_setitem_and_getitem(engine):
-    buffer = engine.create_buffer()
+def test_buffer_setitem_and_getitem(buffer):
+
     buffer.text = "Test text\n\nline2"
     assert len(buffer) == 3
 
     assert buffer[2] == "line2"
 
 
-def test_buffer_get_slice_and_set_slice(engine):
-    buffer = engine.create_buffer()
+def test_buffer_get_slice_and_set_slice(buffer):
+
     buffer.text = "Test\nslicing\nwell"
+
     assert buffer[:2] == ["Test\n", "slicing\n"]
     assert buffer[2:] == ['well']
 
-
     buffer[:2] = ['more\n', 'slicing\n', 'helps\n']
     assert buffer[2] == "helps\n"
 

File vimish/engine.py

View file
     def __init__(self, engine):
         self.engine = engine
         self.text_buffer = TextBuffer()
+        self.bufnr = engine.add(self)
 
     @property
     def text(self):
 
 class Engine(object):
 
-    def create_buffer(self):
-        return Buffer(self)
+    def __init__(self):
+        self.buffers = []
 
+    def add(self, buffer):
+        self.buffers.append(buffer)
+        return len(self.buffers)
 
+    def remove(self, buffer):
+        self.buffers[buffer.burnr] = None
+        buffer.bufnr = None