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", + )); +}