terminal/new: screen scrollClear tests

This commit is contained in:
Mitchell Hashimoto
2024-02-28 09:46:14 -08:00
parent 3842ca9212
commit 26edb51d0c
2 changed files with 121 additions and 1 deletions

View File

@ -4174,6 +4174,7 @@ test "Screen: scrolling with scrollback available doesn't move selection" {
} }
} }
// X
test "Screen: scroll and clear full screen" { test "Screen: scroll and clear full screen" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;
@ -4201,6 +4202,7 @@ test "Screen: scroll and clear full screen" {
} }
} }
// X
test "Screen: scroll and clear partial screen" { test "Screen: scroll and clear partial screen" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;
@ -4228,6 +4230,7 @@ test "Screen: scroll and clear partial screen" {
} }
} }
// X
test "Screen: scroll and clear empty screen" { test "Screen: scroll and clear empty screen" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;
@ -4238,6 +4241,7 @@ test "Screen: scroll and clear empty screen" {
try testing.expectEqual(@as(usize, 0), s.viewport); try testing.expectEqual(@as(usize, 0), s.viewport);
} }
// X
test "Screen: scroll and clear ignore blank lines" { test "Screen: scroll and clear ignore blank lines" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;

View File

@ -375,7 +375,7 @@ pub fn scroll(self: *Screen, behavior: Scroll) void {
/// to be on top. /// to be on top.
pub fn scrollClear(self: *Screen) !void { pub fn scrollClear(self: *Screen) !void {
try self.pages.scrollClear(); try self.pages.scrollClear();
self.cursorAbsolute(0, 0); self.cursorReload();
// No matter what, scrolling marks our image state as dirty since // No matter what, scrolling marks our image state as dirty since
// it could move placements. If there are no placements or no images // it could move placements. If there are no placements or no images
@ -1287,3 +1287,119 @@ test "Screen: scrollback doesn't move viewport if not at bottom" {
try testing.expectEqualStrings("2EFGH\n3IJKL\n4ABCD", contents); try testing.expectEqualStrings("2EFGH\n3IJKL\n4ABCD", contents);
} }
} }
test "Screen: scroll and clear full screen" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 3, 5);
defer s.deinit();
try s.testWriteString("1ABCD\n2EFGH\n3IJKL");
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("1ABCD\n2EFGH\n3IJKL", contents);
}
try s.scrollClear();
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("", contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("1ABCD\n2EFGH\n3IJKL", contents);
}
}
test "Screen: scroll and clear partial screen" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 3, 5);
defer s.deinit();
try s.testWriteString("1ABCD\n2EFGH");
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("1ABCD\n2EFGH", contents);
}
try s.scrollClear();
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("", contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("1ABCD\n2EFGH", contents);
}
}
test "Screen: scroll and clear empty screen" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 3, 5);
defer s.deinit();
try s.scrollClear();
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("", contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("", contents);
}
}
test "Screen: scroll and clear ignore blank lines" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 3, 10);
defer s.deinit();
try s.testWriteString("1ABCD\n2EFGH");
try s.scrollClear();
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("", contents);
}
// Move back to top-left
s.cursorAbsolute(0, 0);
// Write and clear
try s.testWriteString("3ABCD\n");
{
const contents = try s.dumpStringAlloc(alloc, .{ .active = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("3ABCD", contents);
}
try s.scrollClear();
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("", contents);
}
// Move back to top-left
s.cursorAbsolute(0, 0);
try s.testWriteString("X");
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("1ABCD\n2EFGH\n3ABCD\nX", contents);
}
}