diff --git a/src/bot.zig b/src/bot.zig index fceb37e..c35219f 100644 --- a/src/bot.zig +++ b/src/bot.zig @@ -274,24 +274,6 @@ pub const Bot = struct { return (idx - 1) % self.backlog.len; } - fn previous_message(self: *Bot, comptime pred: *const fn (Message) bool) ?Message { - var idx = self.previous_idx(self.top); - while (true) : (idx = self.previous_idx(idx)) { - if (self.backlog[idx] == null) { - return null; - } - const message = self.backlog[idx] orelse unreachable; - if (pred(message)) { - return message; - } - if (idx == self.bottom) { - // reached the start of the list - break; - } - } - return null; - } - fn previous_message_by_author(self: *Bot, author: []const u8, targets: []const u8) ?Message { var idx = self.previous_idx(self.top); while (true) : (idx = self.previous_idx(idx)) { @@ -330,49 +312,6 @@ test "hear_wraps" { try std.testing.expect(bot.no_messages() == 1024); } -test "previous_message" { - var bot = try Bot.init(std.testing.allocator); - defer bot.deinit(); - - const callback = struct { - fn callback(_: Message) bool { - return true; - } - }.callback; - const prev = bot.previous_message(callback); - - try std.testing.expect(prev == null); -} - -test "previous_message1" { - var bot = try Bot.init(std.testing.allocator); - defer bot.deinit(); - var contents: [10][]const u8 = .{undefined} ** 10; - - for (0..10) |i| { - contents[i] = try std.fmt.allocPrint(std.testing.allocator, "{d}", .{i}); - const msg = Message{ - .author = "Jassob", - .timestamp = @as(u32, @intCast(i)), - .content = contents[i], - }; - bot.hear(msg); - } - - const callback = struct { - fn callback(msg: Message) bool { - return std.mem.eql(u8, msg.content, "8"); - } - }.callback; - const prev = bot.previous_message(callback); - - for (contents) |str| { - std.testing.allocator.free(str); - } - - try std.testing.expect(prev != null); -} - test "execute_substitution_no_previous_message" { var bot = try Bot.init(std.testing.allocator); defer bot.deinit();