diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index d069a7f67..5ed7d70a1 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -4339,6 +4339,7 @@ test "Screen: history region with scrollback" { } } +// X - don't need this, internal API test "Screen: row copy" { const testing = std.testing; const alloc = testing.allocator; @@ -4357,6 +4358,7 @@ test "Screen: row copy" { try testing.expectEqualStrings("2EFGH\n3IJKL\n2EFGH", contents); } +// X test "Screen: clone" { const testing = std.testing; const alloc = testing.allocator; @@ -4387,6 +4389,7 @@ test "Screen: clone" { } } +// X test "Screen: clone empty viewport" { const testing = std.testing; const alloc = testing.allocator; @@ -4405,6 +4408,7 @@ test "Screen: clone empty viewport" { } } +// X test "Screen: clone one line viewport" { const testing = std.testing; const alloc = testing.allocator; @@ -4424,6 +4428,7 @@ test "Screen: clone one line viewport" { } } +// X test "Screen: clone empty active" { const testing = std.testing; const alloc = testing.allocator; @@ -4442,6 +4447,7 @@ test "Screen: clone empty active" { } } +// X test "Screen: clone one line active with extra space" { const testing = std.testing; const alloc = testing.allocator; diff --git a/src/terminal/new/Screen.zig b/src/terminal/new/Screen.zig index e1632d8fa..1b6071608 100644 --- a/src/terminal/new/Screen.zig +++ b/src/terminal/new/Screen.zig @@ -1524,3 +1524,130 @@ test "Screen: clone partial" { try testing.expectEqualStrings("2EFGH", contents); } } + +test "Screen: clone basic" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 10, 3, 0); + defer s.deinit(); + try s.testWriteString("1ABCD\n2EFGH\n3IJKL"); + + { + var s2 = try s.clone( + alloc, + .{ .active = .{ .y = 1 } }, + .{ .active = .{ .y = 1 } }, + ); + defer s2.deinit(); + + // Test our contents rotated + const contents = try s2.dumpStringAlloc(alloc, .{ .active = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("2EFGH", contents); + } + + { + var s2 = try s.clone( + alloc, + .{ .active = .{ .y = 1 } }, + .{ .active = .{ .y = 2 } }, + ); + defer s2.deinit(); + + // Test our contents rotated + const contents = try s2.dumpStringAlloc(alloc, .{ .active = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("2EFGH\n3IJKL", contents); + } +} + +test "Screen: clone empty viewport" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 10, 3, 0); + defer s.deinit(); + + { + var s2 = try s.clone( + alloc, + .{ .viewport = .{ .y = 0 } }, + .{ .viewport = .{ .y = 0 } }, + ); + defer s2.deinit(); + + // Test our contents rotated + const contents = try s2.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("", contents); + } +} + +test "Screen: clone one line viewport" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 10, 3, 0); + defer s.deinit(); + try s.testWriteString("1ABC"); + + { + var s2 = try s.clone( + alloc, + .{ .viewport = .{ .y = 0 } }, + .{ .viewport = .{ .y = 0 } }, + ); + defer s2.deinit(); + + // Test our contents + const contents = try s2.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("1ABC", contents); + } +} + +test "Screen: clone empty active" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 10, 3, 0); + defer s.deinit(); + + { + var s2 = try s.clone( + alloc, + .{ .active = .{ .y = 0 } }, + .{ .active = .{ .y = 0 } }, + ); + defer s2.deinit(); + + // Test our contents rotated + const contents = try s2.dumpStringAlloc(alloc, .{ .active = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("", contents); + } +} + +test "Screen: clone one line active with extra space" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 10, 3, 0); + defer s.deinit(); + try s.testWriteString("1ABC"); + + { + var s2 = try s.clone( + alloc, + .{ .active = .{ .y = 0 } }, + null, + ); + defer s2.deinit(); + + // Test our contents rotated + const contents = try s2.dumpStringAlloc(alloc, .{ .active = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("1ABC", contents); + } +}