summaryrefslogtreecommitdiff
path: root/src/colors.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-09 00:52:52 -0300
committerGabriel Schneider <[email protected]>2026-11-09 01:28:28 -0300
commit5157579ff7f9ae0cfc3c7629e953da05bce340fc (patch)
tree02147789efdcea998981efcfe05d4bcb3e9bb7b0 /src/colors.zig
parent4c4b9bf54d77dbc0f9f4e2619746908e501c6001 (diff)
downloadpardes-5157579ff7f9ae0cfc3c7629e953da05bce340fc.tar.gz
pardes-5157579ff7f9ae0cfc3c7629e953da05bce340fc.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/colors.zig')
-rw-r--r--src/colors.zig208
1 files changed, 104 insertions, 104 deletions
diff --git a/src/colors.zig b/src/colors.zig
index cb5dbe75..bc59c334 100644
--- a/src/colors.zig
+++ b/src/colors.zig
@@ -89,60 +89,6 @@ fn focusTint(th: *const Theme) [3]u8 {
return best;
}
-test "every native theme's separators stand off its page, and its focus tint off its tag" {
- for (themes[0..native_count]) |*theme| {
- const chrome = ChromeTheme.fromTheme(theme);
- const page = theme.bg orelse null_page;
- try std.testing.expect(contrast(chrome.border, page) >= separator_floor);
- // A dark page's focused tag is told by its band too, not the grip
- // alone; acme's (light, and acme's own) is told by its button.
- if (relativeLuminance(page) < 0.18) try std.testing.expect(theme.tag_active_bg != null);
- if (theme.tag_active_bg) |own| {
- try std.testing.expect(contrast(chrome.tag_active_bg, theme.tag_bg) >= focusTintFloor(theme));
- // And its text still reads.
- const ink = theme.tag_active_fg orelse theme.tag_fg;
- try std.testing.expect(contrast(ink, chrome.tag_active_bg) >= @min(contrast(ink, own), 4.5) - 0.01);
- }
- }
-}
-
-test "every faithful port meets pardes's chrome floors in its own colours, with nothing left to derive" {
- const first = comptime indexOfTheme("lapis") + 1;
- const last = comptime indexOfTheme("helix");
- for (themes[first..last]) |*th| {
- const chrome = ChromeTheme.fromTheme(th);
- const page = th.bg.?;
- // Written out already adjusted: the run-time lift and push leave
- // the file's own values, so what the file says is what is drawn.
- try std.testing.expectEqual(th.border.?, chrome.border);
- try std.testing.expectEqual(th.tag_active_bg.?, chrome.tag_active_bg);
- try std.testing.expect(contrast(th.border.?, page) >= separator_floor);
- try std.testing.expect(contrast(th.tag_active_bg.?, th.tag_bg) >= focusTintFloor(th));
- try std.testing.expect(contrast(th.tag_fg, th.tag_bg) >= 4.5);
- try std.testing.expect(contrast(th.tag_active_fg.?, th.tag_active_bg.?) >= 4.5);
- try std.testing.expect(contrast(th.box_dim, th.tag_bg) >= 1.5);
- try std.testing.expect(th.palette != null);
- // A status bar of its own reads as tag text does; without one the
- // tagline is the tag's.
- try std.testing.expect(contrast(chrome.tagline_fg, chrome.tagline_bg) >= 4.5);
- if (th.tagline_bg == null) try std.testing.expectEqual(th.tag_bg, chrome.tagline_bg);
- }
-}
-
-test "a derived separator or tint keeps the theme's own when it already stands off" {
- const forge = &themes[
- for (themes[0..native_count], 0..) |t, i| {
- if (std.mem.eql(u8, t.name, "forge")) break i;
- } else unreachable
- ];
- const chrome = ChromeTheme.fromTheme(forge);
- try std.testing.expectEqual(forge.border.?, chrome.border);
- // forge's own tint is 1.23:1 off its tag: pushed on the way it leans.
- try std.testing.expect(!std.meta.eql(forge.tag_active_bg.?, chrome.tag_active_bg));
- for (chrome.tag_active_bg, forge.tag_active_bg.?, forge.tag_bg) |pushed, own, plain|
- try std.testing.expect(pushed >= own and own >= plain);
-}
-
/// sRGB bytes to OKLab and back (Björn Ottosson's), and a mix in it.
fn toOklab(rgb: [3]u8) [3]f32 {
var l: [3]f32 = undefined;
@@ -258,20 +204,6 @@ pub fn nameTintFloor(ink: [3]u8, ground: [3]u8) f32 {
return @min(4.5, contrast(ink, ground) - 0.5);
}
-test "an OKLab fade holds its ends exactly and keeps a mid-way bright" {
- for ([_][3]u8{ .{ 0, 0, 0 }, .{ 255, 255, 255 }, .{ 0x0c, 0x0c, 0x0e }, .{ 0xe8, 0xc4, 0x6a }, .{ 0x1c, 0x51, 0x72 } }) |rgb| {
- try std.testing.expectEqual(rgb, fromOklab(toOklab(rgb)));
- try std.testing.expectEqual(rgb, mixOklab(rgb, .{ 10, 200, 30 }, 0));
- }
- // Red to green through sRGB bytes dips dark at the middle; through
- // OKLab it keeps its lightness.
- const red: [3]u8 = .{ 255, 0, 0 };
- const green: [3]u8 = .{ 0, 200, 0 };
- const srgb_mid = mix(red, green);
- const lab_mid = mixOklab(red, green, 0.5);
- try std.testing.expect(relativeLuminance(lab_mid) > relativeLuminance(srgb_mid) * 1.3);
-}
-
pub fn mix(a: [3]u8, b: [3]u8) [3]u8 {
var out: [3]u8 = undefined;
for (&out, a, b) |*c, x, y| c.* = @intCast((@as(u16, x) + y) / 2);
@@ -506,31 +438,6 @@ pub fn groupAt(index: usize) ?[]const u8 {
return null;
}
-test "the picker's sections run in ring order and cover it" {
- var last: usize = 0;
- inline for (theme_groups, 0..) |g, n| {
- const at = comptime indexOfTheme(g.first);
- if (n == 0) try std.testing.expectEqual(@as(usize, 0), at) else try std.testing.expect(at > last);
- last = at;
- }
- try std.testing.expectEqualStrings("Pardes themes", groupAt(0).?);
- // acme is a current theme, not a legacy one.
- try std.testing.expect(indexOfTheme("acme") < indexOfTheme("helix"));
- try std.testing.expect(groupAt(native_count) != null);
-}
-
-test "seoul256's twelve backgrounds ring in their order, after Catppuccin and before Zenbones" {
- const names = [_][]const u8{
- "seoul256_dark_233", "seoul256_dark_234", "seoul256_dark_235", "seoul256_dark_236",
- "seoul256_dark_237", "seoul256_dark_238", "seoul256_dark_239", "seoul256_light_252",
- "seoul256_light_253", "seoul256_light_254", "seoul256_light_255", "seoul256_light_256",
- };
- const first = indexOfTheme("seoul256_dark_233");
- for (names, themes[first..][0..names.len]) |name, t| try std.testing.expectEqualStrings(name, t.name);
- try std.testing.expectEqualStrings("catppuccin_mocha", themes[first - 1].name);
- try std.testing.expectEqualStrings("zenbones_light", themes[first + names.len].name);
-}
-
/// Original and classic-inspired Pardes palettes precede retained imports.
pub const native_theme_count = 15;
@@ -793,17 +700,6 @@ fn putName(w: *std.Io.Writer, cap: usize, name: []const u8) bool {
return true;
}
-test "a theme hint drops whole names to fit, never cutting one" {
- var buf: [23]u8 = undefined;
- const said = themesNear(&buf, "9dracula");
- var words = std.mem.tokenizeScalar(u8, said, ' ');
- while (words.next()) |word| {
- var whole = false;
- for (themes) |t| whole = whole or std.mem.eql(u8, t.name, word);
- try std.testing.expect(whole);
- }
-}
-
fn likeness(theme_name: []const u8, name: []const u8) usize {
var prefix: usize = 0;
while (prefix < @min(theme_name.len, name.len) and std.ascii.toLower(theme_name[prefix]) == std.ascii.toLower(name[prefix])) prefix += 1;
@@ -845,6 +741,110 @@ pub fn setThemeIndex(p: *Pardes, index: usize) void {
p.settings.theme = @intCast(index);
}
+test "every native theme's separators stand off its page, and its focus tint off its tag" {
+ for (themes[0..native_count]) |*theme| {
+ const chrome = ChromeTheme.fromTheme(theme);
+ const page = theme.bg orelse null_page;
+ try std.testing.expect(contrast(chrome.border, page) >= separator_floor);
+ // A dark page's focused tag is told by its band too, not the grip
+ // alone; acme's (light, and acme's own) is told by its button.
+ if (relativeLuminance(page) < 0.18) try std.testing.expect(theme.tag_active_bg != null);
+ if (theme.tag_active_bg) |own| {
+ try std.testing.expect(contrast(chrome.tag_active_bg, theme.tag_bg) >= focusTintFloor(theme));
+ // And its text still reads.
+ const ink = theme.tag_active_fg orelse theme.tag_fg;
+ try std.testing.expect(contrast(ink, chrome.tag_active_bg) >= @min(contrast(ink, own), 4.5) - 0.01);
+ }
+ }
+}
+
+test "every faithful port meets pardes's chrome floors in its own colours, with nothing left to derive" {
+ const first = comptime indexOfTheme("lapis") + 1;
+ const last = comptime indexOfTheme("helix");
+ for (themes[first..last]) |*th| {
+ const chrome = ChromeTheme.fromTheme(th);
+ const page = th.bg.?;
+ // Written out already adjusted: the run-time lift and push leave
+ // the file's own values, so what the file says is what is drawn.
+ try std.testing.expectEqual(th.border.?, chrome.border);
+ try std.testing.expectEqual(th.tag_active_bg.?, chrome.tag_active_bg);
+ try std.testing.expect(contrast(th.border.?, page) >= separator_floor);
+ try std.testing.expect(contrast(th.tag_active_bg.?, th.tag_bg) >= focusTintFloor(th));
+ try std.testing.expect(contrast(th.tag_fg, th.tag_bg) >= 4.5);
+ try std.testing.expect(contrast(th.tag_active_fg.?, th.tag_active_bg.?) >= 4.5);
+ try std.testing.expect(contrast(th.box_dim, th.tag_bg) >= 1.5);
+ try std.testing.expect(th.palette != null);
+ // A status bar of its own reads as tag text does; without one the
+ // tagline is the tag's.
+ try std.testing.expect(contrast(chrome.tagline_fg, chrome.tagline_bg) >= 4.5);
+ if (th.tagline_bg == null) try std.testing.expectEqual(th.tag_bg, chrome.tagline_bg);
+ }
+}
+
+test "a derived separator or tint keeps the theme's own when it already stands off" {
+ const forge = &themes[
+ for (themes[0..native_count], 0..) |t, i| {
+ if (std.mem.eql(u8, t.name, "forge")) break i;
+ } else unreachable
+ ];
+ const chrome = ChromeTheme.fromTheme(forge);
+ try std.testing.expectEqual(forge.border.?, chrome.border);
+ // forge's own tint is 1.23:1 off its tag: pushed on the way it leans.
+ try std.testing.expect(!std.meta.eql(forge.tag_active_bg.?, chrome.tag_active_bg));
+ for (chrome.tag_active_bg, forge.tag_active_bg.?, forge.tag_bg) |pushed, own, plain|
+ try std.testing.expect(pushed >= own and own >= plain);
+}
+
+test "an OKLab fade holds its ends exactly and keeps a mid-way bright" {
+ for ([_][3]u8{ .{ 0, 0, 0 }, .{ 255, 255, 255 }, .{ 0x0c, 0x0c, 0x0e }, .{ 0xe8, 0xc4, 0x6a }, .{ 0x1c, 0x51, 0x72 } }) |rgb| {
+ try std.testing.expectEqual(rgb, fromOklab(toOklab(rgb)));
+ try std.testing.expectEqual(rgb, mixOklab(rgb, .{ 10, 200, 30 }, 0));
+ }
+ // Red to green through sRGB bytes dips dark at the middle; through
+ // OKLab it keeps its lightness.
+ const red: [3]u8 = .{ 255, 0, 0 };
+ const green: [3]u8 = .{ 0, 200, 0 };
+ const srgb_mid = mix(red, green);
+ const lab_mid = mixOklab(red, green, 0.5);
+ try std.testing.expect(relativeLuminance(lab_mid) > relativeLuminance(srgb_mid) * 1.3);
+}
+
+test "the picker's sections run in ring order and cover it" {
+ var last: usize = 0;
+ inline for (theme_groups, 0..) |g, n| {
+ const at = comptime indexOfTheme(g.first);
+ if (n == 0) try std.testing.expectEqual(@as(usize, 0), at) else try std.testing.expect(at > last);
+ last = at;
+ }
+ try std.testing.expectEqualStrings("Pardes themes", groupAt(0).?);
+ // acme is a current theme, not a legacy one.
+ try std.testing.expect(indexOfTheme("acme") < indexOfTheme("helix"));
+ try std.testing.expect(groupAt(native_count) != null);
+}
+
+test "seoul256's twelve backgrounds ring in their order, after Catppuccin and before Zenbones" {
+ const names = [_][]const u8{
+ "seoul256_dark_233", "seoul256_dark_234", "seoul256_dark_235", "seoul256_dark_236",
+ "seoul256_dark_237", "seoul256_dark_238", "seoul256_dark_239", "seoul256_light_252",
+ "seoul256_light_253", "seoul256_light_254", "seoul256_light_255", "seoul256_light_256",
+ };
+ const first = indexOfTheme("seoul256_dark_233");
+ for (names, themes[first..][0..names.len]) |name, t| try std.testing.expectEqualStrings(name, t.name);
+ try std.testing.expectEqualStrings("catppuccin_mocha", themes[first - 1].name);
+ try std.testing.expectEqualStrings("zenbones_light", themes[first + names.len].name);
+}
+
+test "a theme hint drops whole names to fit, never cutting one" {
+ var buf: [23]u8 = undefined;
+ const said = themesNear(&buf, "9dracula");
+ var words = std.mem.tokenizeScalar(u8, said, ' ');
+ while (words.next()) |word| {
+ var whole = false;
+ for (themes) |t| whole = whole or std.mem.eql(u8, t.name, word);
+ try std.testing.expect(whole);
+ }
+}
+
test "a theme file that cannot be read is named in the failure" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();