pub fn compact(instructions: Option<&str>) -> String {
match instructions {
Some(s) => {
let trimmed = s.trim();
if trimmed.is_empty() {
"/compact".to_string()
} else {
format!("/compact {trimmed}")
}
}
None => "/compact".to_string(),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn compact_without_instructions_is_bare() {
assert_eq!(compact(None), "/compact");
}
#[test]
fn compact_with_instructions_appends_them() {
assert_eq!(
compact(Some("focus on the auth bug")),
"/compact focus on the auth bug"
);
}
#[test]
fn compact_trims_surrounding_whitespace() {
assert_eq!(compact(Some(" keep tests ")), "/compact keep tests");
}
#[test]
fn compact_empty_string_collapses_to_bare() {
assert_eq!(compact(Some("")), "/compact");
assert_eq!(compact(Some(" ")), "/compact");
}
}