terminal/new: more screen tests

This commit is contained in:
Mitchell Hashimoto
2024-02-29 10:46:55 -08:00
parent 07eaedf1fb
commit 07639e48ab
2 changed files with 58 additions and 0 deletions

View File

@ -5414,6 +5414,7 @@ test "Screen: scrollRegionUp buffer wrap alternative with extra lines" {
} }
} }
// X
test "Screen: clear history with no history" { test "Screen: clear history with no history" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;
@ -5438,6 +5439,7 @@ test "Screen: clear history with no history" {
} }
} }
// X
test "Screen: clear history" { test "Screen: clear history" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;
@ -5472,6 +5474,7 @@ test "Screen: clear history" {
} }
} }
// X
test "Screen: clear above cursor" { test "Screen: clear above cursor" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;

View File

@ -1709,3 +1709,58 @@ test "Screen: clear history" {
try testing.expectEqualStrings("4ABCD\n5EFGH\n6IJKL", contents); try testing.expectEqualStrings("4ABCD\n5EFGH\n6IJKL", contents);
} }
} }
test "Screen: clear above cursor" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 10, 3);
defer s.deinit();
try s.testWriteString("4ABCD\n5EFGH\n6IJKL");
s.clearRows(
.{ .active = .{ .y = 0 } },
.{ .active = .{ .y = s.cursor.y - 1 } },
false,
);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("\n\n6IJKL", contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("\n\n6IJKL", contents);
}
try testing.expectEqual(@as(usize, 5), s.cursor.x);
try testing.expectEqual(@as(usize, 2), s.cursor.y);
}
test "Screen: clear above cursor with history" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 3, 3);
defer s.deinit();
try s.testWriteString("1ABCD\n2EFGH\n3IJKL\n");
try s.testWriteString("4ABCD\n5EFGH\n6IJKL");
s.clearRows(
.{ .active = .{ .y = 0 } },
.{ .active = .{ .y = s.cursor.y - 1 } },
false,
);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("\n\n6IJKL", contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("1ABCD\n2EFGH\n3IJKL\n\n\n6IJKL", contents);
}
try testing.expectEqual(@as(usize, 5), s.cursor.x);
try testing.expectEqual(@as(usize, 2), s.cursor.y);
}