terminal/new: screen clone tests

This commit is contained in:
Mitchell Hashimoto
2024-02-29 09:44:08 -08:00
parent e903d5ed22
commit ee6344eac8
2 changed files with 133 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}
}