refactor(commands): move user command tests

This commit just shuffles the test for user commands closer to the
definition of the user commands.
This commit is contained in:
Jacob Jonsson 2026-03-15 13:51:26 +01:00
parent 958c00ce6f
commit 49a6b79fd9
Signed by: Jassob
GPG key ID: 7E30B9B047F7202E

View file

@ -53,6 +53,37 @@ pub const UserCommand = union(enum) {
}
};
test "can parse !help successful" {
try std.testing.expectEqual(
UserCommand.help,
UserCommand.parse("jassob", "!help"),
);
}
test "can parse s/hello/world/ successful" {
try std.testing.expectEqualDeep(
UserCommand{ .substitute = .{
.author = "jassob",
.needle = "hello",
.replacement = "world",
.all = false,
} },
UserCommand.parse("jassob", "s/hello/world/"),
);
}
test "can parse s/hello/world and report failure" {
try std.testing.expectEqualDeep(null, UserCommand.parse("jassob", "s/hello/world"));
}
test "can parse s/hello|world| and report failure" {
try std.testing.expectEqualDeep(null, UserCommand.parse("jassob", "s/hello/world"));
}
test "correctly ignores non-messages when trying to parse" {
try std.testing.expectEqualDeep(null, UserCommand.parse("jassob", "Hello, world"));
}
/// AdminCommand are commands useful for debugging zigeru, since they
/// are more spammy than others they are separated and only sent to
/// #eru-admin.
@ -91,37 +122,6 @@ pub const AdminCommand = union(enum) {
}
};
test "can parse !help successful" {
try std.testing.expectEqual(
UserCommand.help,
UserCommand.parse("jassob", "!help"),
);
}
test "can parse s/hello/world/ successful" {
try std.testing.expectEqualDeep(
UserCommand{ .substitute = .{
.author = "jassob",
.needle = "hello",
.replacement = "world",
.all = false,
} },
UserCommand.parse("jassob", "s/hello/world/"),
);
}
test "can parse s/hello/world and report failure" {
try std.testing.expectEqualDeep(null, UserCommand.parse("jassob", "s/hello/world"));
}
test "can parse s/hello|world| and report failure" {
try std.testing.expectEqualDeep(null, UserCommand.parse("jassob", "s/hello/world"));
}
test "correctly ignores non-messages when trying to parse" {
try std.testing.expectEqualDeep(null, UserCommand.parse("jassob", "Hello, world"));
}
test "parse admin commands" {
const cmd = AdminCommand.parse("!join badchannel") orelse unreachable;
try std.testing.expectEqual(