From 49a6b79fd92bab1b0efa922df3debe3a611c6368 Mon Sep 17 00:00:00 2001 From: Jacob Jonsson Date: Sun, 15 Mar 2026 13:51:26 +0100 Subject: [PATCH] refactor(commands): move user command tests This commit just shuffles the test for user commands closer to the definition of the user commands. --- src/commands.zig | 62 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/commands.zig b/src/commands.zig index b16f3ef..f782830 100644 --- a/src/commands.zig +++ b/src/commands.zig @@ -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(