From a8091fedf324c198e31de5ef6a55393166c5f1e1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 25 Jun 2025 16:18:17 -0400 Subject: [PATCH] fix tests --- src/apprt/gtk/CommandPalette.zig | 1 - src/config/Config.zig | 29 +++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/apprt/gtk/CommandPalette.zig b/src/apprt/gtk/CommandPalette.zig index 3c8192a50..d05f195b3 100644 --- a/src/apprt/gtk/CommandPalette.zig +++ b/src/apprt/gtk/CommandPalette.zig @@ -103,7 +103,6 @@ pub fn updateConfig(self: *CommandPalette, config: *const configpkg.Config) !voi self.source.removeAll(); _ = self.arena.reset(.retain_capacity); - // TODO: Allow user-configured palette entries for (config.@"command-palette-entry".value.items) |command| { // Filter out actions that are not implemented // or don't make sense for GTK diff --git a/src/config/Config.zig b/src/config/Config.zig index eb5c18ea3..6c86de5ac 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -6147,12 +6147,23 @@ pub const RepeatableCommand = struct { try self.value.appendSlice(alloc, inputpkg.command.defaults); } - pub fn parseCLI(self: *RepeatableCommand, alloc: Allocator, input: ?[]const u8) !void { - const input_ = input orelse { + pub fn parseCLI( + self: *RepeatableCommand, + alloc: Allocator, + input_: ?[]const u8, + ) !void { + // Unset or empty input clears the list + const input = input_ orelse ""; + if (input.len == 0) { self.value.clearRetainingCapacity(); return; - }; - const cmd = try cli.args.parseAutoStruct(inputpkg.Command, alloc, input_); + } + + const cmd = try cli.args.parseAutoStruct( + inputpkg.Command, + alloc, + input, + ); try self.value.append(alloc, cmd); } @@ -6214,16 +6225,14 @@ pub const RepeatableCommand = struct { try testing.expectEqual(inputpkg.Binding.Action.ignore, list.value.items[0].action); try testing.expectEqualStrings("Foo", list.value.items[0].title); - try testing.expectEqual( - inputpkg.Binding.Action{ .text = "ale bydle" }, - list.value.items[0].action, - ); + try testing.expect(list.value.items[1].action == .text); + try testing.expectEqualStrings("ale bydle", list.value.items[1].action.text); try testing.expectEqualStrings("Bar", list.value.items[1].title); try testing.expectEqualStrings("bobr", list.value.items[1].description); try testing.expectEqual( inputpkg.Binding.Action{ .increase_font_size = 2.5 }, - list.value.items[0].action, + list.value.items[2].action, ); try testing.expectEqualStrings("Quux", list.value.items[2].title); try testing.expectEqualStrings("boo", list.value.items[2].description); @@ -6270,7 +6279,7 @@ pub const RepeatableCommand = struct { try list.parseCLI(alloc, "title:Bobr, action:text:kurwa"); try list.parseCLI(alloc, "title:Ja, description: pierdole, action:text:jakie bydle"); try list.formatEntry(formatterpkg.entryFormatter("a", buf.writer())); - try std.testing.expectEqualSlices(u8, "a = title:bobr,action:text:kurwa\na = title:Ja,description:pierdole,action:text:jakie bydle\n", buf.items); + try std.testing.expectEqualSlices(u8, "a = title:Bobr,action:text:kurwa\na = title:Ja,description:pierdole,action:text:jakie bydle\n", buf.items); } };