use trustee_core::session::truncate_session_name;
#[test]
fn ascii_long_truncates_identically_to_legacy() {
let cmd = "A".repeat(100);
assert_eq!(truncate_session_name(&cmd), format!("{}...", "A".repeat(77)));
}
#[test]
fn ascii_exactly_80_chars_unchanged() {
let cmd = "A".repeat(80);
assert_eq!(truncate_session_name(&cmd), cmd);
}
#[test]
fn persian_long_does_not_panic_and_cuts_at_boundary() {
let cmd = "ن".repeat(100); let name = truncate_session_name(&cmd);
assert!(name.ends_with("..."));
assert_eq!(name, format!("{}...", "ن".repeat(38)));
}
#[test]
fn persian_short_unchanged() {
let cmd = "سلام دنیا".to_string(); assert_eq!(truncate_session_name(&cmd), cmd);
}
#[test]
fn char_boundary_exactly_at_77_same_as_legacy() {
let cmd = format!("{}{}", "A".repeat(77), "BCDE");
assert_eq!(truncate_session_name(&cmd), format!("{}...", "A".repeat(77)));
}
#[test]
fn four_byte_char_straddling_cut_is_excluded_not_sliced() {
let cmd = "\u{20BB7}".repeat(100); let name = truncate_session_name(&cmd);
assert_eq!(name, format!("{}...", "\u{20BB7}".repeat(19)));
}
#[test]
fn mixed_scripts_never_panic_and_stay_under_budget() {
let cmd = format!("{}{}{}", "abc ".repeat(10), "نص فارسی ".repeat(20), "🙂".repeat(30));
let name = truncate_session_name(&cmd);
assert!(name.ends_with("..."));
assert!(name.len() <= 80, "name body must stay within the byte budget, got {}", name.len());
assert!(name.is_char_boundary(name.len() - 3)); }
#[test]
fn empty_and_single_char_unchanged() {
assert_eq!(truncate_session_name(""), "");
assert_eq!(truncate_session_name("x"), "x");
}