Tests for Cursor

This commit is contained in:
Kovid Goyal 2016-10-16 20:47:00 +05:30
parent adaf748852
commit b9c15ef8e3
2 changed files with 24 additions and 1 deletions

View File

@ -40,8 +40,20 @@ class Cursor:
ans.hidden = self.hidden ans.hidden = self.hidden
ans.fg, ans.bg, ans.decoration_fg = self.fg, self.bg, self.decoration_fg ans.fg, ans.bg, ans.decoration_fg = self.fg, self.bg, self.decoration_fg
ans.bold, ans.italic, ans.reverse, ans.strikethrough = self.bold, self.italic, self.reverse, self.strikethrough ans.bold, ans.italic, ans.reverse, ans.strikethrough = self.bold, self.italic, self.reverse, self.strikethrough
ans.decoration = self.decoration
return ans return ans
def __eq__(self, other):
if not isinstance(other, Cursor):
return False
for x in self.__slots__:
if getattr(self, x) != getattr(other, x):
return False
return True
def __ne__(self, other):
return not self.__eq__(other)
class Line: class Line:

View File

@ -4,7 +4,7 @@
from . import BaseTest, set_text_in_line from . import BaseTest, set_text_in_line
from kitty.data_types import Line from kitty.data_types import Line, Cursor
class TestDataTypes(BaseTest): class TestDataTypes(BaseTest):
@ -13,6 +13,7 @@ class TestDataTypes(BaseTest):
t = 'Testing with simple text' t = 'Testing with simple text'
l = Line(len(t)) l = Line(len(t))
set_text_in_line(l, t) set_text_in_line(l, t)
self.ae(l, l)
self.ae(str(l), t) self.ae(str(l), t)
self.ae(str(l.copy()), t) self.ae(str(l.copy()), t)
l.continued = False l.continued = False
@ -21,3 +22,13 @@ class TestDataTypes(BaseTest):
self.ae(l, l2) self.ae(l, l2)
l2.char[1] = 23 l2.char[1] = 23
self.assertNotEqual(l, l2) self.assertNotEqual(l, l2)
c = Cursor(3, 5)
c.hidden = True
c.bold = c.italic = c.reverse = c.strikethrough = True
c.fg = c.bg = c.decoration_fg = 0x0101
self.ae(c, c)
c2 = c.copy()
self.ae(c, c.copy())
c2.bold = False
self.assertNotEqual(c, c2)