Switch screen tests to use unicode directly

This commit is contained in:
Kovid Goyal 2016-11-23 20:26:29 +05:30
parent 2c3893d8a4
commit 91f80a3c85

View File

@ -13,11 +13,11 @@ class TestScreen(BaseTest):
s = self.create_screen()
# Test in line-wrap, non-insert mode
s.draw(b'a' * 5)
s.draw('a' * 5)
self.ae(str(s.line(0)), 'a' * 5)
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
s.draw(b'b' * 7)
s.draw('b' * 7)
self.assertTrue(s.linebuf.is_continued(1))
self.assertTrue(s.linebuf.is_continued(2))
self.ae(str(s.line(0)), 'a' * 5)
@ -25,18 +25,18 @@ class TestScreen(BaseTest):
self.ae(str(s.line(2)), 'b' * 2 + ' ' * 3)
self.ae(s.cursor.x, 2), self.ae(s.cursor.y, 2)
self.assertChanges(s, ignore='cursor', cells={1: ((0, 4),), 2: ((0, 1),)})
s.draw(b'c' * 15)
s.draw('c' * 15)
self.ae(str(s.line(0)), 'b' * 5)
self.ae(str(s.line(1)), 'bbccc')
# Now test without line-wrap
s.reset(), s.reset_dirty()
s.reset_mode(DECAWM)
s.draw(b'0123456789')
s.draw('0123456789')
self.ae(str(s.line(0)), '01239')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
s.draw(b'ab')
s.draw('ab')
self.ae(str(s.line(0)), '0123b')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(s, ignore='cursor', cells={0: ((4, 4),)})
@ -44,11 +44,11 @@ class TestScreen(BaseTest):
# Now test in insert mode
s.reset(), s.reset_dirty()
s.set_mode(IRM)
s.draw(b'12345' * 5)
s.draw('12345' * 5)
s.cursor_back(5)
self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 4)
s.reset_dirty()
s.draw(b'ab')
s.draw('ab')
self.ae(str(s.line(4)), 'ab123')
self.ae((s.cursor.x, s.cursor.y), (2, 4))
self.assertChanges(s, ignore='cursor', cells={4: ((0, 4),)})
@ -56,36 +56,36 @@ class TestScreen(BaseTest):
def test_draw_char(self):
# Test in line-wrap, non-insert mode
s = self.create_screen()
s.draw('ココx'.encode('utf-8'))
s.draw('ココx')
self.ae(str(s.line(0)), 'ココx')
self.ae(tuple(map(s.line(0).width, range(5))), (2, 0, 2, 0, 1))
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
s.draw('ニチハ'.encode('utf-8'))
s.draw('ニチハ')
self.ae(str(s.line(0)), 'ココx')
self.ae(str(s.line(1)), 'ニチ ')
self.ae(str(s.line(2)), '')
self.assertChanges(s, ignore='cursor', cells={1: ((0, 3),), 2: ((0, 1),)})
self.ae(s.cursor.x, 2), self.ae(s.cursor.y, 2)
s.draw('Ƶ̧\u0308'.encode('utf-8'))
s.draw('Ƶ̧\u0308')
self.ae(str(s.line(2)), 'ハƵ̧\u0308 ')
self.ae(s.cursor.x, 3), self.ae(s.cursor.y, 2)
self.assertChanges(s, ignore='cursor', cells={2: ((2, 2),)})
s.draw(b'xy'), s.draw('\u0306'.encode('utf-8'))
s.draw('xy'), s.draw('\u0306')
self.ae(str(s.line(2)), 'ハƵ̧\u0308xy\u0306')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 2)
self.assertChanges(s, ignore='cursor', cells={2: ((3, 4),)})
s.draw(b'c' * 15)
s.draw('c' * 15)
self.ae(str(s.line(0)), 'ニチ ')
# Now test without line-wrap
s.reset(), s.reset_dirty()
s.reset_mode(DECAWM)
s.draw('0\u030612345\u03066789\u0306'.encode('utf-8'))
s.draw('0\u030612345\u03066789\u0306')
self.ae(str(s.line(0)), '0\u03061239\u0306')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
s.draw('ab\u0306'.encode('utf-8'))
s.draw('ab\u0306')
self.ae(str(s.line(0)), '0\u0306123b\u0306')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(s, ignore='cursor', cells={0: ((4, 4),)})
@ -93,11 +93,11 @@ class TestScreen(BaseTest):
# Now test in insert mode
s.reset(), s.reset_dirty()
s.set_mode(IRM)
s.draw('1\u03062345'.encode('utf-8') * 5)
s.draw('1\u03062345' * 5)
s.cursor_back(5)
self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 4)
s.reset_dirty()
s.draw('a\u0306b'.encode('utf-8'))
s.draw('a\u0306b')
self.ae(str(s.line(4)), 'a\u0306b1\u030623')
self.ae((s.cursor.x, s.cursor.y), (2, 4))
self.assertChanges(s, ignore='cursor', cells={4: ((0, 4),)})
@ -107,7 +107,7 @@ class TestScreen(BaseTest):
def init():
s.reset(), s.reset_dirty()
s.draw(b'abcde')
s.draw('abcde')
s.cursor.bold = True
s.cursor_back(4)
s.reset_dirty()
@ -122,7 +122,7 @@ class TestScreen(BaseTest):
s.insert_characters(20)
self.ae(str(s.line(0)), ' ')
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
s.draw('xココ'.encode('utf-8'))
s.draw('xココ')
s.cursor_back(5)
s.reset_dirty()
s.insert_characters(1)
@ -174,7 +174,7 @@ class TestScreen(BaseTest):
def init():
s.reset()
s.draw(b'12345' * 5)
s.draw('12345' * 5)
s.reset_dirty()
s.cursor.x, s.cursor.y = 2, 1
s.cursor.bold = True
@ -205,7 +205,7 @@ class TestScreen(BaseTest):
def test_cursor_movement(self):
s = self.create_screen()
s.draw(b'12345' * 5)
s.draw('12345' * 5)
s.reset_dirty()
s.cursor_up(2)
self.ae((s.cursor.x, s.cursor.y), (4, 2))
@ -221,12 +221,12 @@ class TestScreen(BaseTest):
self.ae((s.cursor.x, s.cursor.y), (0, 4))
s = self.create_screen()
s.draw(b'12345' * 5)
s.draw('12345' * 5)
s.index()
self.ae(str(s.line(4)), ' ' * 5)
for i in range(4):
self.ae(str(s.line(i)), '12345')
s.draw(b'12345' * 5)
s.draw('12345' * 5)
s.cursor_up(5)
s.reverse_index()
self.ae(str(s.line(0)), ' ' * 5)
@ -235,7 +235,7 @@ class TestScreen(BaseTest):
def test_resize(self):
s = self.create_screen(scrollback=6)
s.draw(''.join([str(i) * s.columns for i in range(s.lines)]).encode('utf-8'))
s.draw(''.join([str(i) * s.columns for i in range(s.lines)]))
s.resize(3, 10)
self.ae(str(s.line(0)), '0'*5 + '1'*5)
self.ae(str(s.line(1)), '2'*5 + '3'*5)