terminal: add test for pagelist to clear styles

This commit is contained in:
Mitchell Hashimoto
2024-06-24 20:58:11 -07:00
parent 368960d76a
commit b62806360b
2 changed files with 51 additions and 4 deletions

View File

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

View File

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