From 7bcfbf175c0354e1b7497a6040d17cdceaf6c292 Mon Sep 17 00:00:00 2001 From: Christian Nennemann Date: Wed, 4 Mar 2026 13:31:19 +0100 Subject: [PATCH] test: add unit tests for v2 REPL split_cmd parsing --- .../quicproquo-client/src/client/v2_repl.rs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/crates/quicproquo-client/src/client/v2_repl.rs b/crates/quicproquo-client/src/client/v2_repl.rs index 823f097..64a8736 100644 --- a/crates/quicproquo-client/src/client/v2_repl.rs +++ b/crates/quicproquo-client/src/client/v2_repl.rs @@ -924,3 +924,52 @@ pub async fn run_v2_repl( client.disconnect(); Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn split_cmd_basic_command() { + assert_eq!(split_cmd("/help"), Some(("/help", ""))); + } + + #[test] + fn split_cmd_command_with_args() { + assert_eq!(split_cmd("/send hello world"), Some(("/send", "hello world"))); + } + + #[test] + fn split_cmd_leading_whitespace() { + assert_eq!(split_cmd(" /quit"), Some(("/quit", ""))); + } + + #[test] + fn split_cmd_non_command() { + assert_eq!(split_cmd("hello"), None); + } + + #[test] + fn split_cmd_empty_input() { + assert_eq!(split_cmd(""), None); + assert_eq!(split_cmd(" "), None); + } + + #[test] + fn split_cmd_slash_only() { + assert_eq!(split_cmd("/"), Some(("/", ""))); + } + + #[test] + fn split_cmd_args_trimmed() { + assert_eq!(split_cmd("/dm alice"), Some(("/dm", "alice"))); + } + + #[test] + fn split_cmd_special_characters() { + assert_eq!( + split_cmd("/send hello! @alice #chan"), + Some(("/send", "hello! @alice #chan")) + ); + } +}