Tests for erasing characters

This commit is contained in:
Kovid Goyal 2024-11-17 13:53:54 +05:30
parent 8f0d291500
commit e10df382f8
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 15 additions and 3 deletions

View file

@ -2438,11 +2438,11 @@ screen_delete_characters(Screen *self, unsigned int count) {
void
screen_erase_characters(Screen *self, unsigned int count) {
// Delete characters replacing them by spaces
// Delete characters clearing the cells
if (count == 0) count = 1;
unsigned int x = self->cursor->x;
unsigned int num = MIN(self->columns - x, count);
nuke_multicell_char_intersecting_with(self, x, x + num, self->cursor->y, self->cursor->y + 1, true);
nuke_multicell_char_intersecting_with(self, x, x + num, self->cursor->y, self->cursor->y + 1, false);
linebuf_init_line(self->linebuf, self->cursor->y);
line_apply_cursor(self->linebuf->line, self->cursor, x, num, true);
linebuf_mark_line_dirty(self->linebuf, self->cursor->y);

View file

@ -224,7 +224,6 @@ def big_a(x, y):
s.cursor.x = 2
s.delete_characters(1)
assert_line('a\0c\0\0\0')
# multiline
s.reset()
s.draw('a'), multicell(s, 'b', scale=2), s.draw('c')
@ -241,3 +240,16 @@ def big_a(x, y):
assert_line('a_\0\0\0\0')
assert_line('__\0\0\0\0', 1)
# Erase characters (aka replace with null)
s.reset()
s.cursor.x = 1
s.draw('a'), multicell(s, 'b', scale=2), s.draw('c')
s.cursor.x = 0
s.erase_characters(1)
assert_line('\0ab_c\0')
s.erase_characters(2)
assert_line('\0\0b_c\0')
assert_line('\0\0__\0\0', 1)
s.erase_characters(3)
assert_line('\0\0\0\0c\0')
assert_line('\0\0\0\0\0\0', 1)