mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
terminal: add test for pagelist to clear styles
This commit is contained in:
@ -4765,6 +4765,56 @@ test "PageList clone partial trimmed left" {
|
|||||||
try testing.expectEqual(@as(usize, 40), s2.totalRows());
|
try testing.expectEqual(@as(usize, 40), s2.totalRows());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "PageList clone partial trimmed left reclaims styles" {
|
||||||
|
const testing = std.testing;
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
|
var s = try init(alloc, 80, 20, null);
|
||||||
|
defer s.deinit();
|
||||||
|
try testing.expectEqual(@as(usize, s.rows), s.totalRows());
|
||||||
|
try s.growRows(30);
|
||||||
|
|
||||||
|
// Style the rows we're trimming
|
||||||
|
{
|
||||||
|
try testing.expect(s.pages.first == s.pages.last);
|
||||||
|
const page = &s.pages.first.?.data;
|
||||||
|
|
||||||
|
const style: stylepkg.Style = .{ .flags = .{ .bold = true } };
|
||||||
|
const style_id = try page.styles.add(page.memory, style);
|
||||||
|
|
||||||
|
var it = s.rowIterator(.left_up, .{ .screen = .{} }, .{ .screen = .{ .y = 9 } });
|
||||||
|
while (it.next()) |p| {
|
||||||
|
const rac = p.rowAndCell();
|
||||||
|
rac.row.styled = true;
|
||||||
|
rac.cell.* = .{
|
||||||
|
.content_tag = .codepoint,
|
||||||
|
.content = .{ .codepoint = 'A' },
|
||||||
|
.style_id = style_id,
|
||||||
|
};
|
||||||
|
page.styles.use(page.memory, style_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're over-counted by 1 because `add` implies `use`.
|
||||||
|
page.styles.release(page.memory, style_id);
|
||||||
|
|
||||||
|
// Expect to have one style
|
||||||
|
try testing.expectEqual(1, page.styles.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
var s2 = try s.clone(.{
|
||||||
|
.top = .{ .screen = .{ .y = 10 } },
|
||||||
|
.memory = .{ .alloc = alloc },
|
||||||
|
});
|
||||||
|
defer s2.deinit();
|
||||||
|
try testing.expectEqual(@as(usize, 40), s2.totalRows());
|
||||||
|
|
||||||
|
{
|
||||||
|
try testing.expect(s2.pages.first == s2.pages.last);
|
||||||
|
const page = &s2.pages.first.?.data;
|
||||||
|
try testing.expectEqual(0, page.styles.count());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test "PageList clone partial trimmed both" {
|
test "PageList clone partial trimmed both" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
@ -339,10 +339,7 @@ pub fn RefCountedSet(
|
|||||||
|
|
||||||
assert(item.meta.ref > 0);
|
assert(item.meta.ref > 0);
|
||||||
item.meta.ref -= 1;
|
item.meta.ref -= 1;
|
||||||
|
if (item.meta.ref == 0) self.living -= 1;
|
||||||
if (item.meta.ref == 0) {
|
|
||||||
self.living -= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Release a specified number of references to an item by its ID.
|
/// Release a specified number of references to an item by its ID.
|
||||||
|
Reference in New Issue
Block a user