summaryrefslogtreecommitdiff
path: root/src/fonts.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/fonts.zig')
-rw-r--r--src/fonts.zig68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/fonts.zig b/src/fonts.zig
index 5f036119..48fa7179 100644
--- a/src/fonts.zig
+++ b/src/fonts.zig
@@ -188,40 +188,6 @@ fn scan(
return arena.dupe(Font, found[0..found_len]) catch &.{};
}
-test "fallback discovery is unique and preserves candidate priority" {
- for (fallback_names, 0..) |name, i| {
- try std.testing.expect(name.len != 0);
- for (fallback_names[0..i]) |prior|
- try std.testing.expect(!std.mem.eql(u8, prior, name));
- }
-
- var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer arena_state.deinit();
- const installed = fallbacks(arena_state.allocator());
- var previous: ?usize = null;
- for (installed) |font| {
- const rank = for (fallback_names, 0..) |name, i| {
- if (std.mem.eql(u8, name, font.name)) break i;
- } else return error.UnknownFallback;
- if (previous) |p| try std.testing.expect(rank > p);
- previous = rank;
- }
-}
-
-test "the picker lists every monospace face rather than the first max_fonts" {
- var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer arena_state.deinit();
- const installed = list(arena_state.allocator(), null);
- // A canary, and only meaningful on a machine that HAS fonts: reaching the
- // cap is the silent cut max_fonts is sized against.
- try std.testing.expect(installed.len < max_fonts);
- // ...and what it does return is sorted.
- for (installed, 0..) |font, i| {
- try std.testing.expect(font.name.len != 0);
- if (i > 0) try std.testing.expect(!std.mem.lessThan(u8, font.name, installed[i - 1].name));
- }
-}
-
/// Is every glyph in this font the same width? The grid is one advance for
/// every column, chosen once from 'M', so a proportional font in it has every
/// row a different length and the mouse pointing at the wrong character: the
@@ -318,6 +284,40 @@ fn writeScratch(path: [:0]const u8, bytes: []const u8) !void {
try std.testing.expectEqual(@as(isize, @intCast(bytes.len)), libc.write(fd, bytes.ptr, bytes.len));
}
+test "fallback discovery is unique and preserves candidate priority" {
+ for (fallback_names, 0..) |name, i| {
+ try std.testing.expect(name.len != 0);
+ for (fallback_names[0..i]) |prior|
+ try std.testing.expect(!std.mem.eql(u8, prior, name));
+ }
+
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const installed = fallbacks(arena_state.allocator());
+ var previous: ?usize = null;
+ for (installed) |font| {
+ const rank = for (fallback_names, 0..) |name, i| {
+ if (std.mem.eql(u8, name, font.name)) break i;
+ } else return error.UnknownFallback;
+ if (previous) |p| try std.testing.expect(rank > p);
+ previous = rank;
+ }
+}
+
+test "the picker lists every monospace face rather than the first max_fonts" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const installed = list(arena_state.allocator(), null);
+ // A canary, and only meaningful on a machine that HAS fonts: reaching the
+ // cap is the silent cut max_fonts is sized against.
+ try std.testing.expect(installed.len < max_fonts);
+ // ...and what it does return is sorted.
+ for (installed, 0..) |font, i| {
+ try std.testing.expect(font.name.len != 0);
+ if (i > 0) try std.testing.expect(!std.mem.lessThan(u8, font.name, installed[i - 1].name));
+ }
+}
+
test "monospaced reads the advances out of a real sfnt layout" {
// A whole font in 92 bytes: the header, a two-record table directory, and
// an hhea + hmtx that between them say "three glyphs, all 600 units wide".