test(terminal/Screen): clearRows with protected cells

This commit is contained in:
Qwerasd
2024-03-29 16:47:53 -04:00
parent 925c7e86a2
commit 5b509f9295

View File

@ -2219,6 +2219,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void {
.content_tag = .codepoint,
.content = .{ .codepoint = c },
.style_id = self.cursor.style_id,
.protected = self.cursor.protected,
};
// If we have a ref-counted style, increase.
@ -2235,6 +2236,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void {
.content_tag = .codepoint,
.content = .{ .codepoint = 0 },
.wide = .spacer_head,
.protected = self.cursor.protected,
};
self.cursor.page_row.wrap = true;
@ -2249,6 +2251,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void {
.content = .{ .codepoint = c },
.style_id = self.cursor.style_id,
.wide = .wide,
.protected = self.cursor.protected,
};
// Write our tail
@ -2257,6 +2260,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void {
.content_tag = .codepoint,
.content = .{ .codepoint = 0 },
.wide = .spacer_tail,
.protected = self.cursor.protected,
};
},
@ -2537,6 +2541,34 @@ test "Screen clearRows active styled line" {
try testing.expectEqualStrings("", str);
}
test "Screen clearRows protected" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try Screen.init(alloc, 80, 24, 1000);
defer s.deinit();
try s.testWriteString("UNPROTECTED");
s.cursor.protected = true;
try s.testWriteString("PROTECTED");
s.cursor.protected = false;
try s.testWriteString("UNPROTECTED");
try s.testWriteString("\n");
s.cursor.protected = true;
try s.testWriteString("PROTECTED");
s.cursor.protected = false;
try s.testWriteString("UNPROTECTED");
s.cursor.protected = true;
try s.testWriteString("PROTECTED");
s.cursor.protected = false;
s.clearRows(.{ .active = .{} }, null, true);
const str = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(str);
try testing.expectEqualStrings(" PROTECTED\nPROTECTED PROTECTED", str);
}
test "Screen eraseRows history" {
const testing = std.testing;
const alloc = testing.allocator;