From eb3323940d08ea8b9acc7180d5430b1b813e87de Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 1 Mar 2024 13:32:53 -0800 Subject: [PATCH] terminal/new: more no reflow tests --- src/terminal/Screen.zig | 3 +++ src/terminal/new/PageList.zig | 21 +++++++++++++++++++++ src/terminal/new/Screen.zig | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 38ddce58f..3ac42f411 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -6226,6 +6226,7 @@ test "Screen: resize (no reflow) less rows with scrollback" { } } +// X // https://github.com/mitchellh/ghostty/issues/1030 test "Screen: resize (no reflow) less rows with empty trailing" { const testing = std.testing; @@ -6251,6 +6252,7 @@ test "Screen: resize (no reflow) less rows with empty trailing" { } } +// X test "Screen: resize (no reflow) empty screen" { const testing = std.testing; const alloc = testing.allocator; @@ -6268,6 +6270,7 @@ test "Screen: resize (no reflow) empty screen" { try testing.expectEqual(@as(usize, 10), s.rowsCapacity()); } +// X test "Screen: resize (no reflow) grapheme copy" { const testing = std.testing; const alloc = testing.allocator; diff --git a/src/terminal/new/PageList.zig b/src/terminal/new/PageList.zig index fbb98b271..8ae1fe63f 100644 --- a/src/terminal/new/PageList.zig +++ b/src/terminal/new/PageList.zig @@ -2158,3 +2158,24 @@ test "PageList resize (no reflow) more rows and less cols" { try testing.expectEqual(@as(usize, 5), cells.len); } } + +test "PageList resize (no reflow) empty screen" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 5, 5, 0); + defer s.deinit(); + + // Resize + try s.resize(.{ .cols = 10, .rows = 10, .reflow = false }); + try testing.expectEqual(@as(usize, 10), s.cols); + try testing.expectEqual(@as(usize, 10), s.rows); + try testing.expectEqual(@as(usize, 10), s.totalRows()); + + var it = s.rowIterator(.{ .screen = .{} }, null); + while (it.next()) |offset| { + const rac = offset.rowAndCell(0); + const cells = offset.page.data.getCells(rac.row); + try testing.expectEqual(@as(usize, 10), cells.len); + } +} diff --git a/src/terminal/new/Screen.zig b/src/terminal/new/Screen.zig index 0ed8a3229..2f214c7cd 100644 --- a/src/terminal/new/Screen.zig +++ b/src/terminal/new/Screen.zig @@ -1971,3 +1971,28 @@ test "Screen: resize (no reflow) less rows with scrollback" { try testing.expectEqualStrings(expected, contents); } } + +// https://github.com/mitchellh/ghostty/issues/1030 +test "Screen: resize (no reflow) less rows with empty trailing" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 5, 3, 5); + defer s.deinit(); + const str = "1\n2\n3\n4\n5\n6\n7\n8"; + try s.testWriteString(str); + try s.scrollClear(); + s.cursorAbsolute(0, 0); + try s.testWriteString("A\nB"); + + const cursor = s.cursor; + try s.resizeWithoutReflow(5, 2); + try testing.expectEqual(cursor.x, s.cursor.x); + try testing.expectEqual(cursor.y, s.cursor.y); + + { + const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("A\nB", contents); + } +}