summaryrefslogtreecommitdiff
path: root/src/font/Atlas.zig
diff options
context:
space:
mode:
authorQwerasd <qwerasd205@users.noreply.github.com>2025-06-30 16:37:26 -0600
committerQwerasd <qwerasd205@users.noreply.github.com>2025-06-30 16:37:26 -0600
commita00a727e779f674b1d79068803dd336d42e372f7 (patch)
treece90002b4fb388d55322129ff7d9045952e3629e /src/font/Atlas.zig
parent05eeaddb0445fb3b2aedd74da00f3b284b329cac (diff)
test(font/Atlas): add test case for `setFromLarger`
Diffstat (limited to 'src/font/Atlas.zig')
-rw-r--r--src/font/Atlas.zig29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/font/Atlas.zig b/src/font/Atlas.zig
index aac2e7e8d..7b31e2794 100644
--- a/src/font/Atlas.zig
+++ b/src/font/Atlas.zig
@@ -587,6 +587,35 @@ test "writing data" {
try testing.expectEqual(@as(u8, 4), atlas.data[66]);
}
+test "writing data from a larger source" {
+ const alloc = testing.allocator;
+ var atlas = try init(alloc, 32, .grayscale);
+ defer atlas.deinit(alloc);
+
+ const reg = try atlas.reserve(alloc, 2, 2);
+ const old = atlas.modified.load(.monotonic);
+ // zig fmt: off
+ atlas.setFromLarger(reg, &[_]u8{
+ 8, 8, 8, 8, 8,
+ 8, 8, 1, 2, 8,
+ 8, 8, 3, 4, 8,
+ 8, 8, 8, 8, 8,
+ }, 5, 2, 1);
+ // zig fmt: on
+ const new = atlas.modified.load(.monotonic);
+ try testing.expect(new > old);
+
+ // 33 because of the 1px border and so on
+ try testing.expectEqual(@as(u8, 1), atlas.data[33]);
+ try testing.expectEqual(@as(u8, 2), atlas.data[34]);
+ try testing.expectEqual(@as(u8, 3), atlas.data[65]);
+ try testing.expectEqual(@as(u8, 4), atlas.data[66]);
+
+ // None of the `8`s from the source data outside of the
+ // specified region should have made it on to the atlas.
+ try testing.expectEqual(null, std.mem.indexOfScalar(u8, atlas.data, 8));
+}
+
test "grow" {
const alloc = testing.allocator;
var atlas = try init(alloc, 4, .grayscale); // +2 for 1px border