chore(bot.zig): remove unused code
This commit is contained in:
parent
24b4a0517c
commit
9bebf066cf
1 changed files with 0 additions and 61 deletions
61
src/bot.zig
61
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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue