use crate::utils::stop_intent::{is_stop_command_or_intent, is_stop_intent, normalize};
#[test]
fn normalize_strips_punctuation_and_case() {
assert_eq!(normalize("STOP!!!"), "stop");
assert_eq!(normalize(" Stop. "), "stop");
assert_eq!(normalize("HOLD ON, BRO!"), "hold on bro");
}
#[test]
fn punctuated_and_shouted_forms_cancel() {
for text in [
"stop",
"STOP!!!",
"Stop.",
" stop ",
"STOP!!!!!!!!",
"stop!",
] {
assert!(is_stop_intent(text), "should cancel: {text:?}");
}
}
#[test]
fn pause_phrases_cancel() {
for text in [
"hold on",
"hold up",
"hang on",
"wait a sec",
"wait a second",
"one moment",
] {
assert!(is_stop_intent(text), "should cancel: {text:?}");
}
}
#[test]
fn a_pause_phrase_opening_a_longer_message_cancels() {
assert!(is_stop_intent(
"HOLD ON BRO! we need to check something first"
));
assert!(is_stop_intent("wait a sec, I need to look at that"));
}
#[test]
fn addressing_the_bot_still_cancels() {
for text in [
"stop crab",
"stop crabs",
"hold on crab",
"hold on crabs",
"stop please",
"stop bro",
"stop now",
] {
assert!(is_stop_intent(text), "should cancel: {text:?}");
}
}
#[test]
fn every_supported_language_can_stop_it() {
for text in [
"stop", "стоп", "подожди", "espera", "pare", "arrete", "attends", "berhenti", "tunggu", ] {
assert!(is_stop_intent(text), "should cancel: {text:?}");
}
}
#[test]
fn instructions_about_stopping_are_not_interrupts() {
for text in [
"stop the docker container",
"wait for the build to finish",
"cancel the subscription",
"can you stop the server please",
"I had to stop working on it yesterday",
"halt the deployment when tests fail",
] {
assert!(!is_stop_intent(text), "must NOT cancel: {text:?}");
}
}
#[test]
fn an_address_term_alone_is_not_an_interrupt() {
for text in ["crab", "crabs", "bot", "please", "bro"] {
assert!(!is_stop_intent(text), "must NOT cancel: {text:?}");
}
}
#[test]
fn empty_and_whitespace_are_not_interrupts() {
for text in ["", " ", "!!!", "..."] {
assert!(!is_stop_intent(text), "must NOT cancel: {text:?}");
}
}
#[test]
fn the_slash_command_still_works_including_the_group_spelling() {
assert!(is_stop_command_or_intent("/stop"));
assert!(is_stop_command_or_intent("/stop@opencrabsbot"));
assert!(is_stop_command_or_intent("/STOP"));
assert!(is_stop_command_or_intent("stop"));
}
#[test]
fn unrelated_slash_commands_never_cancel() {
for text in ["/models", "/help", "/usage", "/new", "/status"] {
assert!(
!is_stop_command_or_intent(text),
"must NOT cancel: {text:?}"
);
}
}