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:

```
<jassob> helo, world!
<jassob> 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.
This commit is contained in:
Jacob Jonsson 2026-03-15 12:38:23 +01:00
parent b0f0daa19d
commit 4f2b9cbce2
Signed by: Jassob
GPG key ID: 7E30B9B047F7202E

View file

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