Finish tests for Line and Cursor
This commit is contained in:
parent
ce8319de94
commit
9de6387e58
@ -54,6 +54,10 @@ class Cursor:
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def __repr__(self):
|
||||
return self.__class__.__name__ + '({})'.format(', '.join(
|
||||
'{}={}'.format(x, getattr(self, x)) for x in self.__slots__))
|
||||
|
||||
|
||||
class Line:
|
||||
|
||||
@ -116,30 +120,17 @@ class Line:
|
||||
to.width[dest] = self.width[src]
|
||||
|
||||
def apply_cursor(self, c: Cursor, at: int=0, num: int=1, clear_char=False, char=' ') -> None:
|
||||
if num < 2:
|
||||
self.fg[at] = c.fg
|
||||
self.bg[at] = c.bg
|
||||
self.bold[at] = c.bold
|
||||
self.italic[at] = c.italic
|
||||
self.reverse[at] = c.reverse
|
||||
self.strikethrough[at] = c.strikethrough
|
||||
self.decoration[at] = c.decoration
|
||||
self.decoration_fg[at] = c.decoration_fg
|
||||
for i in range(at, at + num):
|
||||
self.fg[i] = c.fg
|
||||
self.bg[i] = c.bg
|
||||
self.bold[i] = c.bold
|
||||
self.italic[i] = c.italic
|
||||
self.reverse[i] = c.reverse
|
||||
self.strikethrough[i] = c.strikethrough
|
||||
self.decoration[i] = c.decoration
|
||||
self.decoration_fg[i] = c.decoration_fg
|
||||
if clear_char:
|
||||
self.width[at], self.char[at] = 1, ord(char)
|
||||
else:
|
||||
num = min(len(self) - at, num)
|
||||
at = slice(at, at + num)
|
||||
self.fg[at] = repeat(c.fg, num)
|
||||
self.bg[at] = repeat(c.bg, num)
|
||||
self.bold[at] = repeat(c.bold, num)
|
||||
self.italic[at] = repeat(c.italic, num)
|
||||
self.reverse[at] = repeat(c.reverse, num)
|
||||
self.strikethrough[at] = repeat(c.strikethrough, num)
|
||||
self.decoration[at] = repeat(c.decoration, num)
|
||||
self.decoration_fg[at] = repeat(c.decoration_fg, num)
|
||||
if clear_char:
|
||||
self.width[at], self.char[at] = repeat(1, num), repeat(ord(char), num)
|
||||
self.width[i], self.char[i] = 1, ord(char)
|
||||
|
||||
def cursor_from(self, x: int, ypos: int=0) -> Cursor:
|
||||
c = Cursor(x, ypos)
|
||||
|
||||
@ -28,7 +28,7 @@ class TestDataTypes(BaseTest):
|
||||
c.bold = c.italic = c.reverse = c.strikethrough = True
|
||||
c.fg = c.bg = c.decoration_fg = 0x0101
|
||||
self.ae(c, c)
|
||||
c2 = c.copy()
|
||||
c2, c3 = c.copy(), c.copy()
|
||||
self.ae(c, c.copy())
|
||||
c2.bold = c2.hidden = False
|
||||
self.assertNotEqual(c, c2)
|
||||
@ -36,4 +36,28 @@ class TestDataTypes(BaseTest):
|
||||
self.ae(c2, l.cursor_from(3, ypos=c2.y))
|
||||
l.apply_cursor(c2, 0, len(l))
|
||||
for i in range(len(l)):
|
||||
c2.x = i
|
||||
self.ae(c2, l.cursor_from(i, ypos=c2.y))
|
||||
l = Line(5)
|
||||
l.apply_cursor(c3, 0)
|
||||
l.copy_char(0, l, 1)
|
||||
c3.x, c3.hidden = 1, False
|
||||
self.ae(l.cursor_from(1, ypos=c3.y), c3)
|
||||
|
||||
t = '0123456789'
|
||||
lo = Line(len(t))
|
||||
set_text_in_line(lo, t)
|
||||
l = lo.copy()
|
||||
l.right_shift(4, 2)
|
||||
self.ae(str(l), '0123454567')
|
||||
l = lo.copy()
|
||||
l.right_shift(0, 0)
|
||||
self.ae(l, lo)
|
||||
l.right_shift(0, 1)
|
||||
self.ae(str(l), '0' + t[:-1])
|
||||
l = lo.copy()
|
||||
l.left_shift(0, 2)
|
||||
self.ae(str(l), t[2:] + '89')
|
||||
l = lo.copy()
|
||||
l.left_shift(7, 3)
|
||||
self.ae(str(l), t)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user