From fba9d5ab619dc2b4a4aa87ba56bc22526cb8dae5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 18 Feb 2024 09:50:07 -0800 Subject: [PATCH] terminal/new: style tests --- src/terminal/new/style.zig | 57 ++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/terminal/new/style.zig b/src/terminal/new/style.zig index 78f6b5c4d..a9d949745 100644 --- a/src/terminal/new/style.zig +++ b/src/terminal/new/style.zig @@ -161,30 +161,33 @@ test { _ = Set; } -// test "Set basic usage" { -// const testing = std.testing; -// const alloc = testing.allocator; -// const layout = Set.layoutForCapacity(0, 16); -// const buf = try alloc.alloc(u8, layout.total_size); -// defer alloc.free(buf); -// -// const style: Style = .{ .flags = .{ .bold = true } }; -// -// var set = Set.init(buf, layout); -// -// // Upsert -// const meta = try set.upsert(buf, style); -// try testing.expect(meta.id > 0); -// -// // Second upsert should return the same metadata. -// { -// const meta2 = try set.upsert(buf, style); -// try testing.expectEqual(meta.id, meta2.id); -// } -// -// // Look it up -// { -// const v = set.lookupId(buf, meta.id).?; -// try testing.expect(v.flags.bold); -// } -// } +test "Set basic usage" { + const testing = std.testing; + const alloc = testing.allocator; + const layout = Set.layoutForCapacity(0, 16); + const buf = try alloc.alloc(u8, layout.total_size); + defer alloc.free(buf); + + const style: Style = .{ .flags = .{ .bold = true } }; + + var set = Set.init(buf, layout); + + // Upsert + const meta = try set.upsert(buf, style); + try testing.expect(meta.id > 0); + + // Second upsert should return the same metadata. + { + const meta2 = try set.upsert(buf, style); + try testing.expectEqual(meta.id, meta2.id); + } + + // Look it up + { + const v = set.lookupId(buf, meta.id).?; + try testing.expect(v.flags.bold); + + const v2 = set.lookupId(buf, meta.id).?; + try testing.expectEqual(v, v2); + } +}