Basic tests for HistoryBuf.rewrap

This commit is contained in:
Kovid Goyal
2016-11-20 22:40:43 +05:30
parent 05c6e7733c
commit 7b1591113a
2 changed files with 29 additions and 1 deletions

View File

@@ -136,10 +136,14 @@ push(HistoryBuf *self, PyObject *args) {
}
// Boilerplate {{{
static PyObject* rewrap(HistoryBuf *self, PyObject *args);
#define rewrap_doc ""
static PyMethodDef methods[] = {
METHOD(change_num_of_lines, METH_O)
METHOD(line, METH_O)
METHOD(push, METH_VARARGS)
METHOD(rewrap, METH_VARARGS)
{NULL, NULL, 0, NULL} /* Sentinel */
};
@@ -196,4 +200,10 @@ void historybuf_rewrap(HistoryBuf *self, HistoryBuf *other) {
if (self->count > 0) rewrap_inner(self, other, self->count, NULL);
}
static PyObject*
rewrap(HistoryBuf *self, PyObject *args) {
HistoryBuf *other;
if (!PyArg_ParseTuple(args, "O!", &HistoryBuf_Type, &other)) return NULL;
historybuf_rewrap(self, other);
Py_RETURN_NONE;
}

View File

@@ -310,3 +310,21 @@ class TestDataTypes(BaseTest):
hb.push(lb.line(2))
self.ae(str(hb.line(0)), '2' * hb.xnum)
self.ae(str(hb.line(4)), '1' * hb.xnum)
# rewrap
hb = filled_history_buf(5, 5)
hb2 = HistoryBuf(hb.ynum, hb.xnum)
hb.rewrap(hb2)
for i in range(hb.ynum):
self.ae(hb2.line(i), hb.line(i))
hb2 = HistoryBuf(8, 5)
hb.rewrap(hb2)
for i in range(hb.ynum):
self.ae(hb2.line(i), hb.line(i))
for i in range(hb.ynum, hb2.ynum):
with self.assertRaises(IndexError):
hb2.line(i)
hb2 = HistoryBuf(3, 5)
hb.rewrap(hb2)
for i in range(hb2.ynum):
self.ae(hb2.line(i), hb.line(i))