Test for apply_cursor and cursor_from

This commit is contained in:
Kovid Goyal 2016-10-16 22:44:30 +05:30
parent b9c15ef8e3
commit e08385f991
2 changed files with 12 additions and 1 deletions

View File

@ -141,6 +141,12 @@ class Line:
if clear_char: if clear_char:
self.width[at], self.char[at] = repeat(1, num), repeat(ord(char), num) self.width[at], self.char[at] = repeat(1, num), repeat(ord(char), num)
def cursor_from(self, x: int, ypos: int=0) -> Cursor:
c = Cursor(x, ypos)
c.fg, c.bg, c.decoration, c.decoration_fg = self.fg[x], self.bg[x], self.decoration[x], self.decoration_fg[x]
c.bold, c.italic, c.reverse, c.strikethrough = bool(self.bold[x]), bool(self.italic[x]), bool(self.reverse[x]), bool(self.strikethrough[x])
return c
def copy_slice(self, src, dest, num): def copy_slice(self, src, dest, num):
src, dest = slice(src, src + num), slice(dest, dest + num) src, dest = slice(src, src + num), slice(dest, dest + num)
for a in (self.char, self.fg, self.bg, self.bold, self.italic, self.reverse, self.strikethrough, self.decoration, self.decoration_fg, self.width): for a in (self.char, self.fg, self.bg, self.bold, self.italic, self.reverse, self.strikethrough, self.decoration, self.decoration_fg, self.width):

View File

@ -30,5 +30,10 @@ class TestDataTypes(BaseTest):
self.ae(c, c) self.ae(c, c)
c2 = c.copy() c2 = c.copy()
self.ae(c, c.copy()) self.ae(c, c.copy())
c2.bold = False c2.bold = c2.hidden = False
self.assertNotEqual(c, c2) self.assertNotEqual(c, c2)
l.apply_cursor(c2, 3)
self.ae(c2, l.cursor_from(3, ypos=c2.y))
l.apply_cursor(c2, 0, len(l))
for i in range(len(l)):
self.ae(c2, l.cursor_from(i, ypos=c2.y))