terminal/new: more less cols tests

This commit is contained in:
Mitchell Hashimoto
2024-03-03 21:31:52 -08:00
parent b6de7eca95
commit af3224d5fb
2 changed files with 181 additions and 0 deletions

View File

@ -7341,6 +7341,7 @@ test "Screen: resize less cols with reflow previously wrapped" {
}
}
// X
test "Screen: resize less cols with reflow and scrollback" {
const testing = std.testing;
const alloc = testing.allocator;
@ -7369,6 +7370,7 @@ test "Screen: resize less cols with reflow and scrollback" {
try testing.expectEqual(@as(usize, 2), s.cursor.y);
}
// X
test "Screen: resize less cols with reflow previously wrapped and scrollback" {
const testing = std.testing;
const alloc = testing.allocator;
@ -7442,6 +7444,7 @@ test "Screen: resize less cols with scrollback keeps cursor row" {
try testing.expectEqual(@as(usize, 0), s.cursor.y);
}
// X
test "Screen: resize more rows, less cols with reflow with scrollback" {
const testing = std.testing;
const alloc = testing.allocator;
@ -7480,6 +7483,7 @@ test "Screen: resize more rows, less cols with reflow with scrollback" {
}
}
// X
// This seems like it should work fine but for some reason in practice
// in the initial implementation I found this bug! This is a regression
// test for that.

View File

@ -2879,3 +2879,180 @@ test "Screen: resize less cols with reflow previously wrapped" {
try testing.expectEqualStrings(expected, contents);
}
}
test "Screen: resize less cols with reflow and scrollback" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 5, 3, 5);
defer s.deinit();
const str = "1A\n2B\n3C\n4D\n5E";
try s.testWriteString(str);
// Put our cursor on the end
s.cursorAbsolute(1, s.pages.rows - 1);
{
const list_cell = s.pages.getCell(.{ .active = .{
.x = s.cursor.x,
.y = s.cursor.y,
} }).?;
try testing.expectEqual(@as(u32, 'E'), list_cell.cell.content.codepoint);
}
try s.resize(3, 3);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
const expected = "3C\n4D\n5E";
try testing.expectEqualStrings(expected, contents);
}
// Cursor should be on the last line
try testing.expectEqual(@as(size.CellCountInt, 1), s.cursor.x);
try testing.expectEqual(@as(size.CellCountInt, 2), s.cursor.y);
}
test "Screen: resize less cols with reflow previously wrapped and scrollback" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 5, 3, 2);
defer s.deinit();
const str = "1ABCD2EFGH3IJKL4ABCD5EFGH";
try s.testWriteString(str);
// Check
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
const expected = "3IJKL\n4ABCD\n5EFGH";
try testing.expectEqualStrings(expected, contents);
}
// Put our cursor on the end
s.cursorAbsolute(s.pages.cols - 1, s.pages.rows - 1);
{
const list_cell = s.pages.getCell(.{ .active = .{
.x = s.cursor.x,
.y = s.cursor.y,
} }).?;
try testing.expectEqual(@as(u32, 'H'), list_cell.cell.content.codepoint);
}
try s.resize(3, 3);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
const expected = "CD5\nEFG\nH";
try testing.expectEqualStrings(expected, contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
const expected = "1AB\nCD2\nEFG\nH3I\nJKL\n4AB\nCD5\nEFG\nH";
try testing.expectEqualStrings(expected, contents);
}
// Cursor should be on the last line
try testing.expectEqual(@as(size.CellCountInt, 0), s.cursor.x);
try testing.expectEqual(@as(size.CellCountInt, 2), s.cursor.y);
{
const list_cell = s.pages.getCell(.{ .active = .{
.x = s.cursor.x,
.y = s.cursor.y,
} }).?;
try testing.expectEqual(@as(u32, 'H'), list_cell.cell.content.codepoint);
}
}
test "Screen: resize more rows, less cols with reflow with scrollback" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 5, 3, 3);
defer s.deinit();
const str = "1ABCD\n2EFGH3IJKL\n4MNOP";
try s.testWriteString(str);
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
const expected = "1ABCD\n2EFGH\n3IJKL\n4MNOP";
try testing.expectEqualStrings(expected, contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
const expected = "2EFGH\n3IJKL\n4MNOP";
try testing.expectEqualStrings(expected, contents);
}
try s.resize(2, 10);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
const expected = "BC\nD\n2E\nFG\nH3\nIJ\nKL\n4M\nNO\nP";
try testing.expectEqualStrings(expected, contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
const expected = "1A\nBC\nD\n2E\nFG\nH3\nIJ\nKL\n4M\nNO\nP";
try testing.expectEqualStrings(expected, contents);
}
}
// This seems like it should work fine but for some reason in practice
// in the initial implementation I found this bug! This is a regression
// test for that.
test "Screen: resize more rows then shrink again" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 5, 3, 10);
defer s.deinit();
const str = "1ABC";
try s.testWriteString(str);
// Grow
try s.resize(5, 10);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings(str, contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings(str, contents);
}
// Shrink
try s.resize(5, 3);
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings(str, contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings(str, contents);
}
// Grow again
try s.resize(5, 10);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings(str, contents);
}
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings(str, contents);
}
}