test: add unit tests for v2 REPL split_cmd parsing

This commit is contained in:
2026-03-04 13:31:19 +01:00
parent 75f11cb76b
commit 7bcfbf175c

View File

@@ -924,3 +924,52 @@ pub async fn run_v2_repl(
client.disconnect(); client.disconnect();
Ok(()) 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"))
);
}
}