kitty/kitty_tests/screen.py

103 lines
4.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from . import BaseTest
from kitty.screen import mo
class TestScreen(BaseTest):
def test_draw_fast(self):
# Test in line-wrap, non-insert mode
s, t = self.create_screen()
s.draw(b'a' * 5)
self.ae(str(s.linebuf[0]), 'a' * 5)
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(t, ignore='cursor', cells={0: ((0, 4),)})
s.draw(b'b' * 7)
self.assertTrue(s.linebuf[1].continued)
self.assertTrue(s.linebuf[2].continued)
self.ae(str(s.linebuf[0]), 'a' * 5)
self.ae(str(s.linebuf[1]), 'b' * 5)
self.ae(str(s.linebuf[2]), 'b' * 2 + ' ' * 3)
self.ae(s.cursor.x, 2), self.ae(s.cursor.y, 2)
self.assertChanges(t, ignore='cursor', cells={1: ((0, 4),), 2: ((0, 1),)})
s.draw(b'c' * 15)
self.ae(str(s.linebuf[0]), 'b' * 5)
self.ae(str(s.linebuf[1]), 'bbccc')
# Now test without line-wrap
s.reset(), t.reset()
s.reset_mode(mo.DECAWM)
s.draw(b'0123456789')
self.ae(str(s.linebuf[0]), '01239')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(t, ignore='cursor', cells={0: ((0, 4),)})
s.draw(b'ab')
self.ae(str(s.linebuf[0]), '0123b')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(t, ignore='cursor', cells={0: ((4, 4),)})
# Now test in insert mode
s.reset(), t.reset()
s.set_mode(mo.IRM)
s.draw(b'12345' * 5)
s.cursor_back(5)
self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 4)
t.reset()
s.draw(b'ab')
self.ae(str(s.linebuf[4]), 'ab123')
self.ae((s.cursor.x, s.cursor.y), (2, 4))
self.assertChanges(t, ignore='cursor', cells={4: ((0, 4),)})
def test_draw_char(self):
# Test in line-wrap, non-insert mode
s, t = self.create_screen()
s.draw('ココx'.encode('utf-8'))
self.ae(str(s.linebuf[0]), 'ココx')
self.ae(tuple(map(s.linebuf[0].width, range(5))), (2, 0, 2, 0, 1))
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(t, ignore='cursor', cells={0: ((0, 4),)})
s.draw('ニチハ'.encode('utf-8'))
self.ae(str(s.linebuf[0]), 'ココx')
self.ae(str(s.linebuf[1]), 'ニチ ')
self.ae(str(s.linebuf[2]), '')
self.assertChanges(t, ignore='cursor', cells={0: ((5, 5),), 1: ((0, 3),), 2: ((0, 1),)})
self.ae(s.cursor.x, 2), self.ae(s.cursor.y, 2)
s.draw('Ƶ̧\u0308'.encode('utf-8'))
self.ae(str(s.linebuf[2]), 'ハƵ̧\u0308 ')
self.ae(s.cursor.x, 3), self.ae(s.cursor.y, 2)
self.assertChanges(t, ignore='cursor', cells={2: ((2, 2),)})
s.draw(b'xy'), s.draw('\u0306'.encode('utf-8'))
self.ae(str(s.linebuf[2]), 'ハƵ̧\u0308xy\u0306')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 2)
self.assertChanges(t, ignore='cursor', cells={2: ((3, 4),)})
s.draw(b'c' * 15)
self.ae(str(s.linebuf[0]), 'ニチ ')
# Now test without line-wrap
s.reset(), t.reset()
s.reset_mode(mo.DECAWM)
s.draw('0\u030612345\u03066789\u0306'.encode('utf-8'))
self.ae(str(s.linebuf[0]), '0\u03061239\u0306')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(t, ignore='cursor', cells={0: ((0, 4),)})
s.draw('ab\u0306'.encode('utf-8'))
self.ae(str(s.linebuf[0]), '0\u0306123b\u0306')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(t, ignore='cursor', cells={0: ((4, 4),)})
# Now test in insert mode
s.reset(), t.reset()
s.set_mode(mo.IRM)
s.draw('1\u03062345'.encode('utf-8') * 5)
s.cursor_back(5)
self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 4)
t.reset()
s.draw('a\u0306b'.encode('utf-8'))
self.ae(str(s.linebuf[4]), 'a\u0306b1\u030623')
self.ae((s.cursor.x, s.cursor.y), (2, 4))
self.assertChanges(t, ignore='cursor', cells={4: ((0, 4),)})