From b12af6f21db1205118ee93efb6c15919185c8c54 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 10 Nov 2016 12:05:50 +0530 Subject: [PATCH] Test for LineBuf.clear() Also raise IndexError instead of ValueError for line and char access --- kitty/line-buf.c | 2 +- kitty_tests/datatypes.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/kitty/line-buf.c b/kitty/line-buf.c index 2c80bfef0..009cfd6d0 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -95,7 +95,7 @@ line(LineBuf *self, PyObject *y) { #define line_doc "Return the specified line as a Line object. Note the Line Object is a live view into the underlying buffer. And only a single line object can be used at a time." unsigned long idx = PyLong_AsUnsignedLong(y); if (idx >= self->ynum) { - PyErr_SetString(PyExc_ValueError, "Line number too large"); + PyErr_SetString(PyExc_IndexError, "Line number too large"); return NULL; } self->line->ynum = idx; diff --git a/kitty_tests/datatypes.py b/kitty_tests/datatypes.py index df8ee60f2..adf7bb8e3 100644 --- a/kitty_tests/datatypes.py +++ b/kitty_tests/datatypes.py @@ -126,6 +126,12 @@ class TestDataTypes(BaseTest): self.ae(str(l), '0 00') self.assertEqualAttributes(l.cursor_from(1), l.cursor_from(0)) + lb = filled_line_buf(10, 10, filled_cursor()) + lb.clear() + lb2 = LineBuf(lb.ynum, lb.ynum) + for i in range(lb.ynum): + self.ae(lb.line(i), lb2.line(i)) + def test_line(self): lb = LineBuf(2, 3) for y in range(lb.ynum): @@ -133,9 +139,9 @@ class TestDataTypes(BaseTest): self.ae(str(line), ' ' * lb.xnum) for x in range(lb.xnum): self.ae(line[x], ' ') - with self.assertRaises(ValueError): + with self.assertRaises(IndexError): lb.line(lb.ynum) - with self.assertRaises(ValueError): + with self.assertRaises(IndexError): lb.line(0)[lb.xnum] l = lb.line(0) l.add_combining_char(0, '1')