From 07639e48ab4d509f7e219070644f7e45b0cc8271 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 29 Feb 2024 10:46:55 -0800 Subject: [PATCH] terminal/new: more screen tests --- src/terminal/Screen.zig | 3 ++ src/terminal/new/Screen.zig | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 0bdb7a285..9e7c92861 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -5414,6 +5414,7 @@ test "Screen: scrollRegionUp buffer wrap alternative with extra lines" { } } +// X test "Screen: clear history with no history" { const testing = std.testing; const alloc = testing.allocator; @@ -5438,6 +5439,7 @@ test "Screen: clear history with no history" { } } +// X test "Screen: clear history" { const testing = std.testing; const alloc = testing.allocator; @@ -5472,6 +5474,7 @@ test "Screen: clear history" { } } +// X test "Screen: clear above cursor" { const testing = std.testing; const alloc = testing.allocator; diff --git a/src/terminal/new/Screen.zig b/src/terminal/new/Screen.zig index 4aa67e3a3..46a47f829 100644 --- a/src/terminal/new/Screen.zig +++ b/src/terminal/new/Screen.zig @@ -1709,3 +1709,58 @@ test "Screen: clear history" { 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); +}