mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-06 16:05:05 +02:00
More tests for rewrap
This commit is contained in:
@@ -151,21 +151,15 @@ class Screen:
|
||||
|
||||
"""
|
||||
self.lines, self.columns = lines, columns
|
||||
for hb in (self.tophistorybuf, ):
|
||||
old = hb.copy()
|
||||
hb.clear(), hb.extend(rewrap_lines(old, columns))
|
||||
for lb in (self.main_linebuf, self.alt_linebuf):
|
||||
old_lines = lb[:]
|
||||
lb.clear()
|
||||
lb[:] = rewrap_lines(old_lines, self.columns)
|
||||
while len(lb) < self.lines:
|
||||
lb.append(Line(self.columns))
|
||||
if len(lb) > self.lines:
|
||||
extra = len(lb) - self.lines
|
||||
slc = lb[:extra]
|
||||
del lb[:extra]
|
||||
if lb is self.main_linebuf:
|
||||
self.tophistorybuf.extend(slc)
|
||||
# TODO: Implement rewrap for history buf
|
||||
self.tophistorybuf.clear()
|
||||
is_main = self.linebuf is self.main_linebuf
|
||||
for x in 'main_linebuf alt_linebuf'.split():
|
||||
lb2 = LineBuf(self.lines, self.columns)
|
||||
lb = getattr(self, x)
|
||||
lb.rewrap(lb2)
|
||||
setattr(self, x, lb2)
|
||||
self.linebuf = self.main_linebuf if is_main else self.alt_linebuf
|
||||
|
||||
self.margins = Margins(0, self.lines - 1)
|
||||
self._notify_cursor_position = False
|
||||
|
||||
@@ -10,6 +10,17 @@ from kitty.utils import is_simple_string, wcwidth, sanitize_title
|
||||
from kitty.fast_data_types import LineBuf, Cursor as C, REVERSE
|
||||
|
||||
|
||||
def create_lbuf(*lines):
|
||||
maxw = max(map(len, lines))
|
||||
ans = LineBuf(len(lines), maxw)
|
||||
prev_full_length = False
|
||||
for i, l in enumerate(lines):
|
||||
ans.line(i).set_text(l, 0, len(l), C())
|
||||
ans.set_continued(i, prev_full_length)
|
||||
prev_full_length = len(l) == maxw
|
||||
return ans
|
||||
|
||||
|
||||
class TestDataTypes(BaseTest):
|
||||
|
||||
def test_linebuf(self):
|
||||
@@ -213,16 +224,32 @@ class TestDataTypes(BaseTest):
|
||||
for i in range(lb2.ynum):
|
||||
self.ae(lb2.line(i), lb.line(i + 2))
|
||||
|
||||
def line_comparison(self, lb, *lines):
|
||||
lb2 = LineBuf(len(lines), max(map(len, lines)))
|
||||
lb.rewrap(lb2)
|
||||
for i, l in enumerate(lines):
|
||||
l2 = lb2.line(i)
|
||||
self.ae(l, str(l2))
|
||||
return lb2
|
||||
|
||||
def assertContinued(self, lb, *vals):
|
||||
self.ae(list(vals), [lb.is_continued(i) for i in range(len(vals))])
|
||||
|
||||
def test_rewrap_wider(self):
|
||||
' New buffer wider '
|
||||
lb = LineBuf(5, 5)
|
||||
lb.line(0).set_text('01234', 0, 5, C())
|
||||
lb.line(1).set_text('56789', 0, 5, C())
|
||||
lb.set_continued(1, True)
|
||||
lb2 = LineBuf(2, 6)
|
||||
lb.rewrap(lb2)
|
||||
self.ae(str(lb2.line(0)), '012345')
|
||||
self.ae(str(lb2.line(1)), '6789 ')
|
||||
lb = create_lbuf('0123 ', '56789')
|
||||
lb2 = self.line_comparison(lb, '0123 5', '6789 ', ' ' * 6)
|
||||
self.assertContinued(lb2, False, True)
|
||||
|
||||
lb = create_lbuf('12', 'abc')
|
||||
lb2 = self.line_comparison(lb, '12 ', 'abc ')
|
||||
self.assertContinued(lb2, False, False)
|
||||
|
||||
def test_rewrap_narrower(self):
|
||||
' New buffer narrower '
|
||||
lb = create_lbuf('123 ', 'abcde')
|
||||
lb2 = self.line_comparison(lb, '123', 'abc', 'de ')
|
||||
self.assertContinued(lb2, False, False, True)
|
||||
|
||||
def test_utils(self):
|
||||
d = codecs.getincrementaldecoder('utf-8')('strict').decode
|
||||
|
||||
Reference in New Issue
Block a user