Commits

Ronny Pfannschmidt committed 9c55641

fix various breakages

Comments (0)

Files changed (2)

tests/test_engine.py

 from vimish.buffer import Buffer
 
+import py.test
+from operator import itemgetter
+
 def test_engine_buffer_id(engine):
 
     buffer = Buffer(engine)
 def test_buffer_del_slice(buffer):
 
     buffer.text = "Test\ndelete\na\nslice\n"
+
     del buffer[0]
     assert buffer.text == "delete\na\nslice\n"
+
     del buffer[:2]
     assert buffer.text == "slice\n"
 
 
+def test_buffer_wrong_index(buffer):
+
+    buffer.text = "Test\na\nbuffer"
+    assert py.test.raises(IndexError, "buffer[30]")
+
+
+def test_buffer_negative_index(buffer):
+
+    buffer.text = "Test\na\nbuffer"
+    
+    assert buffer[5:6] == []
+
 
     def _start_iter(self, pos=None):
         if isinstance(pos, int):
+            if pos >= len(self):
+                raise IndexError
             return self._iter_at_line(pos)
         elif pos is None or pos.start is None:
             return self.text_buffer.get_start_iter()
+        elif pos.start >= len(self):
+            return self._stop_iter()
         else:
             return self._iter_at_line(pos.start)
 
             # end of line iter = start of next line
             if pos+1 < len(self):
                 return self._iter_at_line(pos+1)
+            elif pos+1 == len(self):
+                return self._stop_iter()
             else:
-                return self._stop_iter()
+                raise IndexError
         else:
             if pos.stop is None:
                 return self._stop_iter()
-            elif pos.stop <=len(self):
+            elif pos.stop < len(self):
                 return self._iter_at_line(pos.stop)
             else:
-                self._stop_iter()
+                return self._stop_iter()
 
     def _iter_range(self, slice):
         start = self._start_iter(slice)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.