From 5157579ff7f9ae0cfc3c7629e953da05bce340fc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 9 Nov 2026 00:52:52 -0300 Subject: tests: at the end of their files: every top-level test block of the 46 files that had one mid-file (the locality analysis's 45 and test/hxdiff.zig; gui.zig, macos.zig, look, host_io, 9p_io, terminal, tui, mouse, fs, replica, layout among them, 11,429 test lines), with the functions only tests call, moved after the file's code in their order, a mechanical move (.scratch/suites/tests_to_end.py), zig fmt'd; the unit suites pass as before (tui 1486/1487, gui 1536/1537, core 956/956 on both), macos.zig only parse-checked here Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/fonts.zig | 68 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'src/fonts.zig') 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". -- cgit v1.3