From 4f2b9cbce2d48b96004de591d0f236bc02f406a3 Mon Sep 17 00:00:00 2001 From: Jacob Jonsson Date: Sun, 15 Mar 2026 12:38:23 +0100 Subject: [PATCH] test(bot): record recursive substitution test case Found while the IRC users tried to find bugs in the code base. Currently the bot does not "hear" the commands of users, which means that of the following conversation: ``` helo, world! s/helo/hello/ ``` the only heard messages in the backlog would be the first ("helo, world!"), the substitution would be parsed and executed, but not added to the backlog and hence not possible to update. --- src/bot.zig | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/bot.zig b/src/bot.zig index 0694738..f8c9d9e 100644 --- a/src/bot.zig +++ b/src/bot.zig @@ -297,3 +297,33 @@ test "execute substitution with no matching needle" { "#test", )); } + +test "recursive substitutions does not cause issues" { + var bot = try Bot.init(std.testing.allocator); + defer bot.deinit(); + + // hear original message + const msg = try newTestMessage(std.testing.allocator, "original"); + bot.hear(msg); + + // execute substitution + const cmd = UserCommand.init_substitute("jassob", "original", "something else", false); + switch (try bot.execute( + &cmd, + null, + "#test", + )) { + .PRIVMSG => |message| { + try std.testing.expectEqualDeep("jassob: \"something else\"", message.text); + }, + else => unreachable, + } + + // execute second substitution + const cmd2 = UserCommand.init_substitute("jassob", "s/original/something else/", "something else", false); + try std.testing.expectError(Error.NoMessage, bot.execute( + &cmd2, + null, + "#test", + )); +}